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