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

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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