1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: * @package Nette\Caching\Storages
7: */
8:
9:
10:
11: /**
12: * Memory cache storage.
13: *
14: * @author David Grudl
15: * @package Nette\Caching\Storages
16: */
17: class NMemoryStorage extends NObject implements ICacheStorage
18: {
19: /** @var array */
20: private $data = array();
21:
22:
23: /**
24: * Read from cache.
25: * @param string key
26: * @return mixed|NULL
27: */
28: public function read($key)
29: {
30: return isset($this->data[$key]) ? $this->data[$key] : NULL;
31: }
32:
33:
34: /**
35: * Prevents item reading and writing. Lock is released by write() or remove().
36: * @param string key
37: * @return void
38: */
39: public function lock($key)
40: {
41: }
42:
43:
44: /**
45: * Writes item into the cache.
46: * @param string key
47: * @param mixed data
48: * @param array dependencies
49: * @return void
50: */
51: public function write($key, $data, array $dependencies)
52: {
53: $this->data[$key] = $data;
54: }
55:
56:
57: /**
58: * Removes item from the cache.
59: * @param string key
60: * @return void
61: */
62: public function remove($key)
63: {
64: unset($this->data[$key]);
65: }
66:
67:
68: /**
69: * Removes items from the cache by conditions & garbage collector.
70: * @param array conditions
71: * @return void
72: */
73: public function clean(array $conditions)
74: {
75: if (!empty($conditions[NCache::ALL])) {
76: $this->data = array();
77: }
78: }
79:
80: }
81: