1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author @fabfuel <[email protected]> |
4
|
|
|
* @created: 19.06.15 14:52 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Fabfuel\Prophiler\Decorator\Phalcon\Cache; |
8
|
|
|
|
9
|
|
|
use Fabfuel\Prophiler\Decorator\AbstractDecorator; |
10
|
|
|
use Fabfuel\Prophiler\ProfilerInterface; |
11
|
|
|
use Phalcon\Cache\BackendInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class BackendDecorator |
15
|
|
|
* @package Common\Prophiler\Decorator\Phalcon\Cache |
16
|
|
|
*/ |
17
|
|
|
class BackendDecorator extends AbstractDecorator implements BackendInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param BackendInterface $backend |
21
|
|
|
* @param ProfilerInterface $profiler |
22
|
|
|
*/ |
23
|
15 |
|
public function __construct(BackendInterface $backend, ProfilerInterface $profiler) |
24
|
|
|
{ |
25
|
15 |
|
$this->setDecorated($backend); |
26
|
15 |
|
$this->setProfiler($profiler); |
27
|
15 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
15 |
|
public function getComponentName() |
33
|
|
|
{ |
34
|
15 |
|
$class = get_class($this->getDecorated()); |
35
|
15 |
|
$class = basename(str_replace('\\', '/', $class)); |
36
|
15 |
|
return sprintf('Cache %s', $class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Starts a cache. The $keyname allows to identify the created fragment |
41
|
|
|
* |
42
|
|
|
* @param int|string $keyName |
43
|
|
|
* @param int $lifetime |
44
|
|
|
* @return mixed |
45
|
|
|
*/ |
46
|
1 |
|
public function start($keyName, $lifetime = null) |
47
|
|
|
{ |
48
|
1 |
|
return $this->__call('start', [$keyName, $lifetime]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Stops the frontend without store any cached content |
53
|
|
|
* |
54
|
|
|
* @param boolean $stopBuffer |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
1 |
|
public function stop($stopBuffer = null) |
58
|
|
|
{ |
59
|
1 |
|
return $this->__call('stop', [$stopBuffer]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns front-end instance adapter related to the back-end |
64
|
|
|
* |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
1 |
|
public function getFrontend() |
68
|
|
|
{ |
69
|
1 |
|
return $this->__call('getFrontend', []); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the backend options |
74
|
|
|
* |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
1 |
|
public function getOptions() |
78
|
|
|
{ |
79
|
1 |
|
return $this->__call('getOptions', []); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Checks whether the last cache is fresh or cached |
84
|
|
|
* |
85
|
|
|
* @return boolean |
86
|
|
|
*/ |
87
|
1 |
|
public function isFresh() |
88
|
|
|
{ |
89
|
1 |
|
return $this->__call('isFresh', []); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Checks whether the cache has starting buffering or not |
94
|
|
|
* |
95
|
|
|
* @return boolean |
96
|
|
|
*/ |
97
|
1 |
|
public function isStarted() |
98
|
|
|
{ |
99
|
1 |
|
return $this->__call('isStarted', []); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Sets the last key used in the cache |
104
|
|
|
* |
105
|
|
|
* @param string $lastKey |
106
|
|
|
* @return mixed |
107
|
|
|
*/ |
108
|
1 |
|
public function setLastKey($lastKey) |
109
|
|
|
{ |
110
|
1 |
|
return $this->__call('setLastKey', [$lastKey]); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Gets the last key stored by the cache |
115
|
|
|
* |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
1 |
|
public function getLastKey() |
119
|
|
|
{ |
120
|
1 |
|
return $this->__call('getLastKey', []); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Returns a cached content |
125
|
|
|
* |
126
|
|
|
* @param int|string $keyName |
127
|
|
|
* @param int $lifetime |
128
|
|
|
* @return mixed |
129
|
|
|
*/ |
130
|
1 |
|
public function get($keyName, $lifetime = null) |
131
|
|
|
{ |
132
|
1 |
|
return $this->__call('get', [$keyName, $lifetime]); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Stores cached content into the file backend and stops the frontend |
137
|
|
|
* |
138
|
|
|
* @param int|string $keyName |
139
|
|
|
* @param string $content |
140
|
|
|
* @param int $lifetime |
141
|
|
|
* @param boolean $stopBuffer |
142
|
|
|
* @return mixed |
143
|
|
|
*/ |
144
|
1 |
|
public function save($keyName = null, $content = null, $lifetime = null, $stopBuffer = null) |
145
|
|
|
{ |
146
|
1 |
|
return $this->__call('save', [$keyName, $content, $lifetime, $stopBuffer]); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Deletes a value from the cache by its key |
151
|
|
|
* |
152
|
|
|
* @param int|string $keyName |
153
|
|
|
* @return boolean |
154
|
|
|
*/ |
155
|
1 |
|
public function delete($keyName) |
156
|
|
|
{ |
157
|
1 |
|
return $this->__call('delete', [$keyName]); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Query the existing cached keys |
162
|
|
|
* |
163
|
|
|
* @param string $prefix |
164
|
|
|
* @return array |
165
|
|
|
*/ |
166
|
1 |
|
public function queryKeys($prefix = null) |
167
|
|
|
{ |
168
|
1 |
|
return $this->__call('queryKeys', [$prefix]); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Checks if cache exists and it hasn't expired |
173
|
|
|
* |
174
|
|
|
* @param string $keyName |
175
|
|
|
* @param int $lifetime |
176
|
|
|
* @return boolean |
177
|
|
|
*/ |
178
|
1 |
|
public function exists($keyName = null, $lifetime = null) |
179
|
|
|
{ |
180
|
1 |
|
return $this->__call('exists', [$keyName, $lifetime]); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Immediately invalidates all existing items. |
185
|
|
|
* |
186
|
|
|
* @return boolean |
187
|
|
|
*/ |
188
|
1 |
|
public function flush() |
189
|
|
|
{ |
190
|
1 |
|
return $this->__call('flush', []); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|