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: * @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 NMemoryStorage extends NObject 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: * Prevents item reading and writing. Lock is released by write() or remove().
42: * @param string key
43: * @return void
44: */
45: public function lock($key)
46: {
47: }
48:
49:
50:
51: /**
52: * Writes item into the cache.
53: * @param string key
54: * @param mixed data
55: * @param array dependencies
56: * @return void
57: */
58: public function write($key, $data, array $dp)
59: {
60: $this->data[$key] = $data;
61: }
62:
63:
64:
65: /**
66: * Removes item from the cache.
67: * @param string key
68: * @return void
69: */
70: public function remove($key)
71: {
72: unset($this->data[$key]);
73: }
74:
75:
76:
77: /**
78: * Removes items from the cache by conditions & garbage collector.
79: * @param array conditions
80: * @return void
81: */
82: public function clean(array $conds)
83: {
84: if (!empty($conds[NCache::ALL])) {
85: $this->data = array();
86: }
87: }
88:
89: }
90: