Show
Ignore:
Timestamp:
07/12/08 04:43:43 (4 months ago)
Author:
MattRead
Message:

plugin:staticcache use cache groups, and add basic stats.. very basic ;)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/staticcache/trunk/staticcache.plugin.php

    r594 r672  
    3535         
    3636        //don't cache pages matching ignore list keywords 
    37         if ( preg_match( "@.*($ignore_list).*@i", $request ) || !Options::get( 'staticcache__ignore_list' ) ) { 
     37        if ( preg_match( "@.*($ignore_list).*@i", $request ) ) { 
    3838            return; 
    3939        } 
     
    4242        $query_id = self::get_query_id(); 
    4343         
    44         if ( Cache::has( "staticcache:$request_id" ) ) { 
    45             $cache = Cache::get( "staticcache:$request_id" ); 
     44        if ( Cache::has( array("staticcache", $request_id) ) ) { 
     45            $cache = Cache::get( array("staticcache", $request_id) ); 
    4646            if ( isset( $cache[$query_id] ) ) { 
    4747                global $profile_start; 
     
    4949                $time = microtime(true) - $profile_start; 
    5050                echo "<!-- Served by StaticCache in $time seconds -->"; 
     51                Options::set( 
     52                    'staticcache__average_time', 
     53                    ( Options::get('staticcache__average_time') + $time ) / 2 
     54                ); 
    5155                exit; 
    5256            } 
     
    5559    } 
    5660     
    57     public function cache_invalidate( $url ) 
     61    public function filter_dash_modules( $modules ) 
     62    { 
     63        $this->add_template( 'static_cache_stats', dirname( __FILE__ ) . '/dash_module_staticcache.php' ); 
     64        $modules[] = 'Static Cache'; 
     65        return $modules; 
     66    } 
     67     
     68    public function filter_dash_module_static_cache( $module, $id, $theme ) 
     69    { 
     70        $theme->static_cache_average = sprintf( '%0.4f', Options::get('staticcache__average_time') ); 
     71        $theme->static_cache_pages = count( Cache::get_group('staticcache') ); 
     72        $module['content'] = $theme->fetch( 'static_cache_stats' ); 
     73        return $module; 
     74    } 
     75     
     76    public function cache_invalidate( $urls ) 
    5877    { 
    5978        foreach ( Users::get_all() as $user ) { 
    60             $request_id = self::get_request_id( $user->id, $url ); 
    61             if ( Cache::has( "staticcache:$request_id" ) ) { 
    62                 Cache::expire( "staticcache:$request_id" ); 
     79            foreach( $urls as $url ) { 
     80                $request_id = self::get_request_id( $user->id, $url ); 
     81                if ( Cache::has( array("staticcache", $request_id) ) ) { 
     82                    Cache::expire( array("staticcache", $request_id) ); 
     83                } 
    6384            } 
    6485        } 
     
    7596            $post->comment_feed_link, 
    7697            $post->permalink, 
    77             URL::get( 'atom_feed', 'index=1' ) 
     98            URL::get( 'atom_feed', 'index=1' ), 
     99            Site::get_url( 'habari' ) 
    78100            ); 
    79101        $this->cache_invalidate( $urls ); 
     
    90112            $comment->post->comment_feed_link, 
    91113            $comment->post->permalink, 
    92             URL::get( 'atom_feed', 'index=1' ) 
     114            URL::get( 'atom_feed', 'index=1' ), 
     115            Site::get_url( 'habari' ) 
    93116            ); 
    94117        $this->cache_invalidate( $urls ); 
     
    156179    $query_id = StaticCache::get_query_id(); 
    157180     
    158     if ( Cache::has( "staticcache:$request_id" ) ) { 
    159         $cache = Cache::get( "staticcache:$request_id" ); 
     181    if ( Cache::has( array("staticcache", $request_id) ) ) { 
     182        $cache = Cache::get( array("staticcache", $request_id) ); 
    160183        $cache[$query_id] = $buffer; 
    161184    } 
    162185    else { 
    163         $cache = array( $request_id => array( $query_id => $buffer ) ); 
     186        $cache = array( $query_id => $buffer ); 
    164187    } 
    165     Cache::set( "staticcache:$request_id", $cache ); 
     188    Cache::set( array("staticcache", $request_id), $cache ); 
    166189     
    167190    return false; 
    168191} 
    169192 
    170  
    171193?>