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