with ArmorySync my cache grew to about 10000 files in it. As there is no way to do a "smart" cleanup yet(Nobody wants to delete the whole cache) here is a proposal for keeping the amount of files on a fixed level. With every cache write the amount will randomly shortened to to that fixed amount. Checking the age of every cache item and delete the oldest one, would cost to much time, so the answer is random deletes. The amount could be set by config.
So what do you think?
- Code: Select all
--- D:/xampp/roster.com/htdocs/lib/cache.php.org Sun Sep 02 01:32:52 2007
+++ D:/xampp/roster.com/htdocs/lib/cache.php Tue Sep 25 23:53:24 2007
@@ -60,6 +60,25 @@
}
/**
+ * Maint function to clean cache directory
+ * optional prefix arg
+ *
+ * @param string $prefix
+ */
+ function _cleanCacheRandom( $prefix=null )
+ {
+ $files = glob($this->cache_dir . $prefix . '*');
+ $file_count = count( $files );
+ if ( $file_count > 100 ) {
+ $del_need = $file_count - 100;
+ $rnd = array_rand( $files, $del_need );
+ foreach ( $rnd as $element ) {
+ @unlink( $files[$element] );
+ }
+ }
+ }
+
+ /**
* check the object cache for $cache_file
* returns true if cache file exists and not expired
*
@@ -226,6 +245,7 @@
flock($file, LOCK_UN);
fclose($file);
+ $this->_cleanCacheRandom();
return true;
}