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