1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Provides caching functionality as a mock-up |
5
|
|
|
* |
6
|
|
|
* PHP Version 5 |
7
|
|
|
* |
8
|
|
|
* @category Core |
9
|
|
|
* @package Cache |
10
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
11
|
|
|
* @copyright 2013 cSphere Team |
12
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
13
|
|
|
* @link http://www.csphere.eu |
14
|
|
|
**/ |
15
|
|
|
|
16
|
|
|
namespace csphere\core\cache; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Provides caching functionality as a mock-up |
20
|
|
|
* |
21
|
|
|
* @category Core |
22
|
|
|
* @package Cache |
23
|
|
|
* @author Hans-Joachim Piepereit <[email protected]> |
24
|
|
|
* @copyright 2013 cSphere Team |
25
|
|
|
* @license http://opensource.org/licenses/bsd-license Simplified BSD License |
26
|
|
|
* @link http://www.csphere.eu |
27
|
|
|
**/ |
28
|
|
|
|
29
|
|
|
class Driver_None extends Base |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Keep cache content for current request |
33
|
|
|
**/ |
34
|
|
|
private $_history = []; |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Clears the cache content |
38
|
|
|
* |
39
|
|
|
* @return boolean |
40
|
|
|
**/ |
|
|
|
|
41
|
|
|
|
42
|
|
|
public function clear() |
43
|
|
|
{ |
44
|
|
|
$this->_history = []; |
45
|
|
|
|
46
|
|
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Removes a cached key |
51
|
|
|
* |
52
|
|
|
* @param string $key Name of the key |
53
|
|
|
* @param int $ttl Time to life used for the key |
54
|
|
|
* |
55
|
|
|
* @return boolean |
56
|
|
|
**/ |
|
|
|
|
57
|
|
|
|
58
|
|
|
public function delete($key, $ttl = 0) |
59
|
|
|
{ |
60
|
|
|
unset($this->_history[$key], $ttl); |
61
|
|
|
|
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns a formatted array with statistics |
67
|
|
|
* |
68
|
|
|
* @return array |
69
|
|
|
**/ |
|
|
|
|
70
|
|
|
|
71
|
|
|
public function info() |
72
|
|
|
{ |
73
|
|
|
$info = parent::info(); |
74
|
|
|
|
75
|
|
|
$info['version'] = ''; |
76
|
|
|
$info['client'] = ''; |
77
|
|
|
$info['server'] = ''; |
78
|
|
|
$info['keys'] = count($this->_history); |
79
|
|
|
|
80
|
|
|
return $info; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns a formatted array with all keys and additional information |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
**/ |
|
|
|
|
88
|
|
|
|
89
|
|
|
public function keys() |
90
|
|
|
{ |
91
|
|
|
$time = time(); |
92
|
|
|
$info = []; |
93
|
|
|
|
94
|
|
|
ksort($this->_history); |
95
|
|
|
|
96
|
|
|
foreach ($this->_history AS $key => $value) { |
97
|
|
|
|
98
|
|
|
$info[] = ['name' => $key, 'time' => $time, 'size' => '']; |
99
|
|
|
|
100
|
|
|
unset($value); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $info; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Fetches the desired key |
108
|
|
|
* |
109
|
|
|
* @param string $key Name of the key |
110
|
|
|
* @param int $ttl Time to life used for the key |
111
|
|
|
* |
112
|
|
|
* @return array |
113
|
|
|
**/ |
|
|
|
|
114
|
|
|
|
115
|
|
|
public function load($key, $ttl = 0) |
116
|
|
|
{ |
117
|
|
|
$result = isset($this->_history[$key]) ? $this->_history[$key] : false; |
118
|
|
|
|
119
|
|
|
unset($ttl); |
120
|
|
|
|
121
|
|
|
return $result; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Stores the key with its value in the cache |
126
|
|
|
* |
127
|
|
|
* @param string $key Name of the key |
128
|
|
|
* @param array $value Content to be stored |
129
|
|
|
* @param int $ttl Time to life used for the key |
130
|
|
|
* |
131
|
|
|
* @return boolean |
132
|
|
|
**/ |
|
|
|
|
133
|
|
|
|
134
|
|
|
public function save($key, $value, $ttl = 0) |
135
|
|
|
{ |
136
|
|
|
$this->log($key); |
137
|
|
|
|
138
|
|
|
$this->_history[$key] = $value; |
139
|
|
|
|
140
|
|
|
unset($ttl); |
141
|
|
|
|
142
|
|
|
return true; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|