Skip to content

Commit effe6b1

Browse files
committed
MAGETWO-45775: Cache storage separation support
1 parent d951a20 commit effe6b1

File tree

1 file changed

+23
-102
lines changed

1 file changed

+23
-102
lines changed

lib/internal/Magento/Framework/Cache/Backend/RemoteSynchronizedCache.php

Lines changed: 23 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
/**
1010
* 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
1114
*/
1215
class RemoteSynchronizedCache extends \Zend_Cache_Backend implements \Zend_Cache_Backend_ExtendedInterface
1316
{
@@ -57,7 +60,7 @@ public function __construct(array $options = [])
5760
$universalOptions = array_diff_key($options, $this->_options);
5861

5962
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');
6164
} elseif ($this->_options['remote_backend'] instanceof \Zend_Cache_Backend_ExtendedInterface) {
6265
$this->remote = $this->_options['remote_backend'];
6366
} else {
@@ -67,15 +70,15 @@ public function __construct(array $options = [])
6770
$this->_options['remote_backend_custom_naming'],
6871
$this->_options['remote_backend_autoload']
6972
);
70-
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->remote))) {
73+
if (!($this->remote instanceof \Zend_Cache_Backend_ExtendedInterface)) {
7174
\Zend_Cache::throwException(
7275
'remote_backend must implement the Zend_Cache_Backend_ExtendedInterface interface'
7376
);
7477
}
7578
}
7679

7780
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');
7982
} elseif ($this->_options['local_backend'] instanceof \Zend_Cache_Backend_ExtendedInterface) {
8083
$this->local = $this->_options['local_backend'];
8184
} else {
@@ -85,7 +88,7 @@ public function __construct(array $options = [])
8588
$this->_options['local_backend_custom_naming'],
8689
$this->_options['local_backend_autoload']
8790
);
88-
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->local))) {
91+
if (!($this->local instanceof \Zend_Cache_Backend_ExtendedInterface)) {
8992
\Zend_Cache::throwException(
9093
'local_backend must implement the Zend_Cache_Backend_ExtendedInterface interface'
9194
);
@@ -103,24 +106,17 @@ private function updateRemoteCacheStatusInfo()
103106
$this->remote->save(time(), $this->_options['remote_backend_invalidation_time_id'], [], null);
104107
$this->cacheInvalidationTime = null;
105108
}
109+
106110
/**
107-
* Set the frontend directives
108-
*
109-
* @param array $directives assoc of directives
111+
* {@inheritdoc}
110112
*/
111113
public function setDirectives($directives)
112114
{
113115
return $this->local->setDirectives($directives);
114116
}
115117

116118
/**
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}
124120
*/
125121
public function load($id, $doNotTestCacheValidity = false)
126122
{
@@ -136,39 +132,23 @@ public function load($id, $doNotTestCacheValidity = false)
136132
}
137133

138134
/**
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}
143136
*/
144137
public function test($id)
145138
{
146139
return $this->local->test($id);
147140
}
148141

149142
/**
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}
160144
*/
161145
public function save($data, $id, $tags = [], $specificLifetime = false)
162146
{
163147
return $this->local->save($data, $id, $tags, $specificLifetime);
164148
}
165149

166150
/**
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}
172152
*/
173153
public function remove($id)
174154
{
@@ -177,22 +157,7 @@ public function remove($id)
177157
}
178158

179159
/**
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}
196161
*/
197162
public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, $tags = [])
198163
{
@@ -201,115 +166,71 @@ public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, $tags = [])
201166
}
202167

203168
/**
204-
* Return an array of stored cache ids
205-
*
206-
* @return array array of stored cache ids (string)
169+
* {@inheritdoc}
207170
*/
208171
public function getIds()
209172
{
210173
return $this->local->getIds();
211174
}
212175

213176
/**
214-
* Return an array of stored tags
215-
*
216-
* @return array array of stored tags (string)
177+
* {@inheritdoc}
217178
*/
218179
public function getTags()
219180
{
220181
return $this->local->getTags();
221182
}
222183

223184
/**
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}
230186
*/
231187
public function getIdsMatchingTags($tags = [])
232188
{
233189
return $this->local->getIdsMatchingTags($tags);
234190
}
235191

236192
/**
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}
243194
*/
244195
public function getIdsNotMatchingTags($tags = [])
245196
{
246197
return $this->local->getIdsNotMatchingTags($tags);
247198
}
248199

249200
/**
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}
256202
*/
257203
public function getIdsMatchingAnyTags($tags = [])
258204
{
259205
return $this->local->getIdsMatchingAnyTags($tags);
260206
}
261207

262208
/**
263-
* Return the filling percentage of the backend storage
264-
*
265-
* @return int integer between 0 and 100
209+
* {@inheritdoc}
266210
*/
267211
public function getFillingPercentage()
268212
{
269213
return $this->local->getFillingPercentage();
270214
}
271215

272216
/**
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}
282218
*/
283219
public function getMetadatas($id)
284220
{
285221
return $this->local->getMetadatas($id);
286222
}
287223

288224
/**
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}
294226
*/
295227
public function touch($id, $extraLifetime)
296228
{
297229
return $this->local->touch($id, $extraLifetime);
298230
}
299231

300232
/**
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}
313234
*/
314235
public function getCapabilities()
315236
{

0 commit comments

Comments
 (0)