Proposal for keeping amount of cache on a fixed number

Posts from previous Beta sessions

Proposal for keeping amount of cache on a fixed number

Postby poetter » Tue Sep 25, 2007 6:12 am

Hi,

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;
    }
    

Image
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

Proposal for keeping amount of cache on a fixed number

Postby zanix » Tue Sep 25, 2007 6:19 am

Sounds like a good idea, hope ds sees this
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US

Proposal for keeping amount of cache on a fixed number

Postby ds » Tue Sep 25, 2007 7:17 am

That is a pretty good idea... I was also thinking of adding the maint hooks as an upload trigger. But this is a great idea as well. Esp for the guild sites that might use ArmorySync exclusively. I'll add this to official code and put in the configuration ASAP. Thanks!

-ds
Image
ds
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 297
Joined: Sat Jul 08, 2006 9:58 am

Proposal for keeping amount of cache on a fixed number

Postby poetter » Tue Sep 25, 2007 7:23 am

Your welcome.

Please do some more testing. That was a quick hack and i got undefined index notices for the foreach command. Can't be a big thing.
Image
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

Proposal for keeping amount of cache on a fixed number

Postby zanix » Tue Sep 25, 2007 7:51 am

Oh don't worry, DS is a very good coder
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US


Return to Archived

Who is online

Users browsing this forum: No registered users and 1 guest

cron