Changeset 2505

Show
Ignore:
Timestamp:
06/04/08 07:54:01 (17 months ago)
Author:
fumiakiy
Message:

Purge stale search cache after it finishes processing, and also periodically. BugId:79999

Location:
branches/release-39/lib/MT
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/release-39/lib/MT/App/Search.pm

    r2463 r2505  
    173173        return; 
    174174    } 
    175     $app->{cache_driver} = $cache_driver->new( ttl => $app->config->SearchCacheTTL ); 
     175    $app->{cache_driver} = $cache_driver->new( 
     176        ttl => $app->config->SearchCacheTTL, 
     177        kind => 'CS', 
     178    ); 
    176179} 
    177180 
     
    877880    my ( $cb, $app ) = @_; 
    878881    alarm(0) if $app->{__have_throttle}; 
     882    if ( my $cache_driver = $app->{cache_driver} ) { 
     883        $cache_driver->purge_stale( 2 * $app->config->SearchCacheTTL ); 
     884    } 
    879885    1; 
    880886} 
  • branches/release-39/lib/MT/Cache/Null.pm

    r2027 r2505  
    5454} 
    5555 
     56sub purge_stale { 
     57    my MT::Cache::Null $self = shift; 
     58    return; 
     59} 
     60 
    5661sub flush_all { 
    5762    my MT::Cache::Null $self = shift; 
  • branches/release-39/lib/MT/Cache/Session.pm

    r1596 r2505  
    1414    my (%param) = @_; 
    1515    $param{'ttl'} ||= 0; 
     16    $param{'kind'} ||= 'CO'; 
    1617    my $self = bless \%param, $class; 
    1718    return $self; 
     
    2526    if ( $self->{ttl} ) { 
    2627        $record = MT::Session::get_unexpired_value( 
    27             $self->{ttl}, { id => $key, kind => 'CO' } ); 
     28            $self->{ttl}, { id => $key, kind => $self->{kind} } ); 
    2829    } 
    2930    else { 
    30         $record = MT::Session->load( { id => $key, kind => 'CO' } ); 
     31        $record = MT::Session->load( { id => $key, kind => $self->{kind} } ); 
    3132    } 
    3233    return unless $record; 
     
    3839    my @keys = @_; 
    3940 
    40     my @tmp = MT::Session->load( { id => \@keys, kind => 'CO' } ) 
     41    my @tmp = MT::Session->load( { id => \@keys, kind => $self->{kind} } ) 
    4142        or return; 
    4243 
     
    6162    my MT::Cache::Session $self = shift; 
    6263    my ($key, $time) = @_; 
    63     MT::Session->remove( { id => $key, kind => 'CO' } ) 
     64    MT::Session->remove( { id => $key, kind => $self->{kind} } ) 
    6465        or return 0; 
    6566    1; 
     
    8687    my $cache = MT::Session->load({ 
    8788        id   => $key, 
    88         kind => 'CO', 
     89        kind => $self->{kind}, 
    8990    }); 
    9091    $cache->remove() if $cache; 
     
    9293    $cache->set_values({ 
    9394        id    => $key, 
    94         kind  => 'CO', 
     95        kind  => $self->{kind}, 
    9596        start => time, 
    9697        data  => $val, 
     
    101102sub flush_all { 
    102103    my MT::Cache::Session $self = shift; 
    103     MT::Session->remove({ kind => 'CO' }); 
     104    MT::Session->remove({ kind => $self->{kind} }); 
     105} 
     106 
     107sub purge_stale { 
     108    my MT::Cache::Session $self = shift; 
     109    my ( $ttl ) = @_; 
     110    MT::Session->remove( 
     111        { kind => $self->{kind}, start => [ undef, time - $ttl ] }, 
     112        { range => { start => 1 } } 
     113    ); 
     114    1; 
    104115} 
    105116 
     
    150161Empty all the caches. 
    151162 
     163=head2 $cache->purge_stale 
     164 
     165Deletes all the cached objects that are already too old. 
     166Takes one argument: $ttl specifies the duration that is considered stale. 
     167 
    152168=head1 AUTHOR & COPYRIGHT 
    153169 
  • branches/release-39/lib/MT/Core.pm

    r2377 r2505  
    774774            }, 
    775775        }, 
     776        'RemoveExpiredSearchCaches' => { 
     777            label => 'Remove Expired Search Caches', 
     778            frequency => 60 * 60 * 24,   # once a day 
     779            code => sub { 
     780                MT::Core->remove_expired_search_caches; 
     781            }, 
     782        }, 
    776783    }; 
    777784} 
     
    803810        $s->remove if !$s->get('remember'); 
    804811    } 
     812    return ''; 
     813} 
     814 
     815sub remove_expired_search_caches { 
     816    require MT::Session; 
     817 
     818    MT::Session->remove( 
     819        { kind => 'CS', start => [ undef, time - 60 * 60 ] }, 
     820        { range => { start => 1 } } ); 
    805821    return ''; 
    806822} 
  • branches/release-39/lib/MT/Memcached.pm

    r2253 r2505  
    5151        $driver_class->disconnect_all; 
    5252    } 
     53} 
     54 
     55# method for MT::Cache interface 
     56sub purge_stale { 
     57    1; 
    5358} 
    5459