1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004, 2011 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: * @package Nette\Caching\Storages
11: */
12:
13:
14:
15: /**
16: * Memory cache storage.
17: *
18: * @author David Grudl
19: * @package Nette\Caching\Storages
20: */
21: class MemoryStorage extends Object implements ICacheStorage
22: {
23: /** @var array */
24: private $data = array();
25:
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: /**
41: * Writes item into the cache.
42: * @param string key
43: * @param mixed data
44: * @param array dependencies
45: * @return void
46: */
47: public function write($key, $data, array $dp)
48: {
49: $this->data[$key] = $data;
50: }
51:
52:
53:
54: /**
55: * Removes item from the cache.
56: * @param string key
57: * @return void
58: */
59: public function remove($key)
60: {
61: unset($this->data[$key]);
62: }
63:
64:
65:
66: /**
67: * Removes items from the cache by conditions & garbage collector.
68: * @param array conditions
69: * @return void
70: */
71: public function clean(array $conds)
72: {
73: if (!empty($conds[Cache::ALL])) {
74: $this->data = array();
75: }
76: }
77:
78: }
79: