[Slim-Checkins] r10209 - in /trunk/server: Slim/Utils/Cache.pm
slimserver.pl
andy at svn.slimdevices.com
andy at svn.slimdevices.com
Thu Oct 5 08:31:46 PDT 2006
Author: andy
Date: Thu Oct 5 08:31:45 2006
New Revision: 10209
URL: http://svn.slimdevices.com?rev=10209&view=rev
Log:
Instead of relying on FileCache's auto-purge, clean the cache up ourselves once an hour or so
Modified:
trunk/server/Slim/Utils/Cache.pm
trunk/server/slimserver.pl
Modified: trunk/server/Slim/Utils/Cache.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Cache.pm?rev=10209&r1=10208&r2=10209&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Cache.pm (original)
+++ trunk/server/Slim/Utils/Cache.pm Thu Oct 5 08:31:45 2006
@@ -41,7 +41,21 @@
use strict;
use base qw(Class::Singleton);
use Cache::FileCache ();
+use Slim::Utils::Misc;
use Slim::Utils::Prefs;
+use Slim::Utils::Timers;
+
+my $PURGE_INTERVAL = 3600;
+
+sub init {
+ my $class = shift;
+
+ # Clean up the cache at startup
+ __PACKAGE__->new->purge();
+
+ # And continue to clean it up regularly
+ Slim::Utils::Timers::setTimer( undef, time() + $PURGE_INTERVAL, \&cleanup );
+}
sub new { shift->instance(@_) }
@@ -49,11 +63,10 @@
my $class = shift;
my $cache = Cache::FileCache->new( {
- namespace => 'FileCache',
- default_expires_in => $Cache::FileCache::EXPIRES_NEVER,
- cache_root => Slim::Utils::Prefs::get('cachedir'),
- directory_umask => umask(),
- auto_purge_interval => '1 hour',
+ namespace => 'FileCache',
+ default_expires_in => $Cache::FileCache::EXPIRES_NEVER,
+ cache_root => Slim::Utils::Prefs::get('cachedir'),
+ directory_umask => umask(),
} );
my $self = bless {
@@ -78,4 +91,36 @@
return $self;
}
+sub cleanup {
+
+ # Use the same method the Scheduler uses to run only when idle
+ my $busy;
+
+ for my $client ( Slim::Player::Client::clients() ) {
+
+ if (Slim::Player::Source::playmode($client) eq 'play' &&
+ $client->isPlayer() &&
+ $client->usage() < 0.5) {
+
+ $busy = 1;
+ last;
+ }
+ }
+
+ if ( !$busy ) {
+ $::d_server && msg("Cache: Cleaning up expired items...\n");
+
+ __PACKAGE__->new->purge();
+
+ $::d_server && msg("Cache: Done\n");
+
+ Slim::Utils::Timers::setTimer( undef, time() + $PURGE_INTERVAL, \&cleanup );
+ }
+ else {
+ # try again soon
+ $::d_server && msg("Cache: Skipping cleanup, server is busy\n");
+ Slim::Utils::Timers::setTimer( undef, time() + ($PURGE_INTERVAL / 6), \&cleanup );
+ }
+}
+
1;
Modified: trunk/server/slimserver.pl
URL: http://svn.slimdevices.com/trunk/server/slimserver.pl?rev=10209&r1=10208&r2=10209&view=diff
==============================================================================
--- trunk/server/slimserver.pl (original)
+++ trunk/server/slimserver.pl Thu Oct 5 08:31:45 2006
@@ -138,6 +138,7 @@
use Slim::Player::Playlist;
use Slim::Player::Sync;
use Slim::Player::Source;
+use Slim::Utils::Cache;
use Slim::Utils::Prefs;
use Slim::Utils::Scanner;
use Slim::Utils::Scheduler;
@@ -391,6 +392,9 @@
$::d_server && msg("Async Networking init...\n");
Slim::Networking::Async->init;
+
+ $::d_server && msg("Cache init, cleaning up FileCache...\n");
+ Slim::Utils::Cache->init;
unless ( $noupnp ) {
$::d_server && msg("UPnP init...\n");
More information about the checkins
mailing list