@@ -238,10 +238,6 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
238
238
$ dataToSave = $ data ;
239
239
$ remHash = $ this ->loadRemoteDataVersion ($ id );
240
240
241
- if ($ this ->checkLocalCacheSpace ()) {
242
- $ this ->local ->clean ();
243
- }
244
-
245
241
if ($ remHash !== false && $ this ->getDataVersion ($ data ) === $ remHash ) {
246
242
$ dataToSave = $ this ->remote ->load ($ id );
247
243
} else {
@@ -253,6 +249,10 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
253
249
$ this ->unlock ($ id );
254
250
}
255
251
252
+ if (!mt_rand (0 , 100 ) && $ this ->checkIfLocalCacheSpaceExceeded ()) {
253
+ $ this ->local ->clean ();
254
+ }
255
+
256
256
return $ this ->local ->save ($ dataToSave , $ id , [], $ specificLifetime );
257
257
}
258
258
@@ -261,34 +261,9 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
261
261
*
262
262
* @return bool
263
263
*/
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 ()
280
265
{
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 ' ];
292
267
}
293
268
294
269
/**
0 commit comments