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