Skip to content

Commit fa35718

Browse files
committed
MCP-103: L2 cache local flushing issues
1 parent 59c6c50 commit fa35718

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

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

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,6 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
238238
$dataToSave = $data;
239239
$remHash = $this->loadRemoteDataVersion($id);
240240

241-
if ($this->checkLocalCacheSpace()) {
242-
$this->local->clean();
243-
}
244-
245241
if ($remHash !== false && $this->getDataVersion($data) === $remHash) {
246242
$dataToSave = $this->remote->load($id);
247243
} else {
@@ -253,6 +249,10 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
253249
$this->unlock($id);
254250
}
255251

252+
if (!mt_rand(0, 100) && $this->checkIfLocalCacheSpaceExceeded()) {
253+
$this->local->clean();
254+
}
255+
256256
return $this->local->save($dataToSave, $id, [], $specificLifetime);
257257
}
258258

@@ -261,34 +261,9 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
261261
*
262262
* @return bool
263263
*/
264-
private function checkLocalCacheSpace()
265-
{
266-
return
267-
(
268-
$this->getDirectorySize($this->_options['local_backend_options']['cache_dir'])
269-
) / 1024 / 1024 >=
270-
$this->_options['local_backend_max_size'];
271-
}
272-
273-
/**
274-
* Get directory size
275-
*
276-
* @param $directory
277-
* @return int
278-
*/
279-
private function getDirectorySize($directory)
264+
private function checkIfLocalCacheSpaceExceeded()
280265
{
281-
$it = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS);
282-
$ri = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
283-
284-
$size = 0;
285-
foreach ($ri as $file) {
286-
if ($file->isFile()) {
287-
$size += $file->getSize();
288-
}
289-
}
290-
291-
return $size;
266+
return $this->getFillingPercentage() >= $this->_options['local_backend_max_size'];
292267
}
293268

294269
/**

0 commit comments

Comments
 (0)