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: /**
19: * Memory cache storage.
20: *
21: * @author David Grudl
22: */
23: class MemoryStorage extends Nette\Object implements Nette\Caching\IStorage
24: {
25: /** @var array */
26: private $data = array();
27:
28:
29:
30: /**
31: * Read from cache.
32: * @param string key
33: * @return mixed|NULL
34: */
35: public function read($key)
36: {
37: return isset($this->data[$key]) ? $this->data[$key] : NULL;
38: }
39:
40:
41:
42: /**
43: * Prevents item reading and writing. Lock is released by write() or remove().
44: * @param string key
45: * @return void
46: */
47: public function lock($key)
48: {
49: }
50:
51:
52:
53: /**
54: * Writes item into the cache.
55: * @param string key
56: * @param mixed data
57: * @param array dependencies
58: * @return void
59: */
60: public function write($key, $data, array $dp)
61: {
62: $this->data[$key] = $data;
63: }
64:
65:
66:
67: /**
68: * Removes item from the cache.
69: * @param string key
70: * @return void
71: */
72: public function remove($key)
73: {
74: unset($this->data[$key]);
75: }
76:
77:
78:
79: /**
80: * Removes items from the cache by conditions & garbage collector.
81: * @param array conditions
82: * @return void
83: */
84: public function clean(array $conds)
85: {
86: if (!empty($conds[Nette\Caching\Cache::ALL])) {
87: $this->data = array();
88: }
89: }
90:
91: }
92: