8
8
9
9
/**
10
10
* Remote synchronized cache
11
+ *
12
+ * This class created for correct work local caches with multiple web nodes,
13
+ * that will be check cache status from remote cache
11
14
*/
12
15
class RemoteSynchronizedCache extends \Zend_Cache_Backend implements \Zend_Cache_Backend_ExtendedInterface
13
16
{
@@ -57,7 +60,7 @@ public function __construct(array $options = [])
57
60
$ universalOptions = array_diff_key ($ options , $ this ->_options );
58
61
59
62
if ($ this ->_options ['remote_backend ' ] === null ) {
60
- \Zend_Cache::throwException ('remote_backend option has to set ' );
63
+ \Zend_Cache::throwException ('remote_backend option must be set ' );
61
64
} elseif ($ this ->_options ['remote_backend ' ] instanceof \Zend_Cache_Backend_ExtendedInterface) {
62
65
$ this ->remote = $ this ->_options ['remote_backend ' ];
63
66
} else {
@@ -67,15 +70,15 @@ public function __construct(array $options = [])
67
70
$ this ->_options ['remote_backend_custom_naming ' ],
68
71
$ this ->_options ['remote_backend_autoload ' ]
69
72
);
70
- if (!in_array ( ' Zend_Cache_Backend_ExtendedInterface ' , class_implements ( $ this ->remote ) )) {
73
+ if (!( $ this ->remote instanceof \Zend_Cache_Backend_ExtendedInterface )) {
71
74
\Zend_Cache::throwException (
72
75
'remote_backend must implement the Zend_Cache_Backend_ExtendedInterface interface '
73
76
);
74
77
}
75
78
}
76
79
77
80
if ($ this ->_options ['local_backend ' ] === null ) {
78
- \Zend_Cache::throwException ('local_backend option has to set ' );
81
+ \Zend_Cache::throwException ('local_backend option must be set ' );
79
82
} elseif ($ this ->_options ['local_backend ' ] instanceof \Zend_Cache_Backend_ExtendedInterface) {
80
83
$ this ->local = $ this ->_options ['local_backend ' ];
81
84
} else {
@@ -85,7 +88,7 @@ public function __construct(array $options = [])
85
88
$ this ->_options ['local_backend_custom_naming ' ],
86
89
$ this ->_options ['local_backend_autoload ' ]
87
90
);
88
- if (!in_array ( ' Zend_Cache_Backend_ExtendedInterface ' , class_implements ( $ this ->local ) )) {
91
+ if (!( $ this ->local instanceof \Zend_Cache_Backend_ExtendedInterface )) {
89
92
\Zend_Cache::throwException (
90
93
'local_backend must implement the Zend_Cache_Backend_ExtendedInterface interface '
91
94
);
@@ -103,24 +106,17 @@ private function updateRemoteCacheStatusInfo()
103
106
$ this ->remote ->save (time (), $ this ->_options ['remote_backend_invalidation_time_id ' ], [], null );
104
107
$ this ->cacheInvalidationTime = null ;
105
108
}
109
+
106
110
/**
107
- * Set the frontend directives
108
- *
109
- * @param array $directives assoc of directives
111
+ * {@inheritdoc}
110
112
*/
111
113
public function setDirectives ($ directives )
112
114
{
113
115
return $ this ->local ->setDirectives ($ directives );
114
116
}
115
117
116
118
/**
117
- * Test if a cache is available for the given id and (if yes) return it (false else)
118
- *
119
- * Note : return value is always "string" (unserialization is done by the core not by the backend)
120
- *
121
- * @param string $id Cache id
122
- * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
123
- * @return string|false cached datas
119
+ * {@inheritdoc}
124
120
*/
125
121
public function load ($ id , $ doNotTestCacheValidity = false )
126
122
{
@@ -136,39 +132,23 @@ public function load($id, $doNotTestCacheValidity = false)
136
132
}
137
133
138
134
/**
139
- * Test if a cache is available or not (for the given id)
140
- *
141
- * @param string $id cache id
142
- * @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
135
+ * {@inheritdoc}
143
136
*/
144
137
public function test ($ id )
145
138
{
146
139
return $ this ->local ->test ($ id );
147
140
}
148
141
149
142
/**
150
- * Save some string datas into a cache record
151
- *
152
- * Note : $data is always "string" (serialization is done by the
153
- * core not by the backend)
154
- *
155
- * @param string $data Datas to cache
156
- * @param string $id Cache id
157
- * @param array $tags Array of strings, the cache record will be tagged by each string entry
158
- * @param integer|bool $specificLifetime
159
- * @return boolean true if no problem
143
+ * {@inheritdoc}
160
144
*/
161
145
public function save ($ data , $ id , $ tags = [], $ specificLifetime = false )
162
146
{
163
147
return $ this ->local ->save ($ data , $ id , $ tags , $ specificLifetime );
164
148
}
165
149
166
150
/**
167
- * Remove a cache record
168
- * Removing any cache item in the RemoteSynchronizedCache must invalidate all cache items
169
- *
170
- * @param string $id Cache id
171
- * @return boolean True if no problem
151
+ * {@inheritdoc}
172
152
*/
173
153
public function remove ($ id )
174
154
{
@@ -177,22 +157,7 @@ public function remove($id)
177
157
}
178
158
179
159
/**
180
- * Clean some cache records
181
- * Cleaning any cache item in the RemoteSynchronizedCache must invalidate all cache items
182
- *
183
- * Available modes are :
184
- * Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
185
- * Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
186
- * Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
187
- * ($tags can be an array of strings or a single string)
188
- * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
189
- * ($tags can be an array of strings or a single string)
190
- * Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
191
- * ($tags can be an array of strings or a single string)
192
- *
193
- * @param string $mode Clean mode
194
- * @param array $tags Array of tags
195
- * @return boolean true if no problem
160
+ * {@inheritdoc}
196
161
*/
197
162
public function clean ($ mode = \Zend_Cache::CLEANING_MODE_ALL , $ tags = [])
198
163
{
@@ -201,115 +166,71 @@ public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, $tags = [])
201
166
}
202
167
203
168
/**
204
- * Return an array of stored cache ids
205
- *
206
- * @return array array of stored cache ids (string)
169
+ * {@inheritdoc}
207
170
*/
208
171
public function getIds ()
209
172
{
210
173
return $ this ->local ->getIds ();
211
174
}
212
175
213
176
/**
214
- * Return an array of stored tags
215
- *
216
- * @return array array of stored tags (string)
177
+ * {@inheritdoc}
217
178
*/
218
179
public function getTags ()
219
180
{
220
181
return $ this ->local ->getTags ();
221
182
}
222
183
223
184
/**
224
- * Return an array of stored cache ids which match given tags
225
- *
226
- * In case of multiple tags, a logical AND is made between tags
227
- *
228
- * @param array $tags array of tags
229
- * @return array array of matching cache ids (string)
185
+ * {@inheritdoc}
230
186
*/
231
187
public function getIdsMatchingTags ($ tags = [])
232
188
{
233
189
return $ this ->local ->getIdsMatchingTags ($ tags );
234
190
}
235
191
236
192
/**
237
- * Return an array of stored cache ids which don't match given tags
238
- *
239
- * In case of multiple tags, a logical OR is made between tags
240
- *
241
- * @param array $tags array of tags
242
- * @return array array of not matching cache ids (string)
193
+ * {@inheritdoc}
243
194
*/
244
195
public function getIdsNotMatchingTags ($ tags = [])
245
196
{
246
197
return $ this ->local ->getIdsNotMatchingTags ($ tags );
247
198
}
248
199
249
200
/**
250
- * Return an array of stored cache ids which match any given tags
251
- *
252
- * In case of multiple tags, a logical AND is made between tags
253
- *
254
- * @param array $tags array of tags
255
- * @return array array of any matching cache ids (string)
201
+ * {@inheritdoc}
256
202
*/
257
203
public function getIdsMatchingAnyTags ($ tags = [])
258
204
{
259
205
return $ this ->local ->getIdsMatchingAnyTags ($ tags );
260
206
}
261
207
262
208
/**
263
- * Return the filling percentage of the backend storage
264
- *
265
- * @return int integer between 0 and 100
209
+ * {@inheritdoc}
266
210
*/
267
211
public function getFillingPercentage ()
268
212
{
269
213
return $ this ->local ->getFillingPercentage ();
270
214
}
271
215
272
216
/**
273
- * Return an array of metadatas for the given cache id
274
- *
275
- * The array must include these keys :
276
- * - expire : the expire timestamp
277
- * - tags : a string array of tags
278
- * - mtime : timestamp of last modification time
279
- *
280
- * @param string $id cache id
281
- * @return array array of metadatas (false if the cache id is not found)
217
+ * {@inheritdoc}
282
218
*/
283
219
public function getMetadatas ($ id )
284
220
{
285
221
return $ this ->local ->getMetadatas ($ id );
286
222
}
287
223
288
224
/**
289
- * Give (if possible) an extra lifetime to the given cache id
290
- *
291
- * @param string $id cache id
292
- * @param int $extraLifetime
293
- * @return boolean true if ok
225
+ * {@inheritdoc}
294
226
*/
295
227
public function touch ($ id , $ extraLifetime )
296
228
{
297
229
return $ this ->local ->touch ($ id , $ extraLifetime );
298
230
}
299
231
300
232
/**
301
- * Return an associative array of capabilities (booleans) of the backend
302
- *
303
- * The array must include these keys :
304
- * - automatic_cleaning (is automating cleaning necessary)
305
- * - tags (are tags supported)
306
- * - expired_read (is it possible to read expired cache records
307
- * (for doNotTestCacheValidity option for example))
308
- * - priority does the backend deal with priority when saving
309
- * - infinite_lifetime (is infinite lifetime can work with this backend)
310
- * - get_list (is it possible to get the list of cache ids and the complete list of tags)
311
- *
312
- * @return array associative of with capabilities
233
+ * {@inheritdoc}
313
234
*/
314
235
public function getCapabilities ()
315
236
{
0 commit comments