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