Show
Ignore:
Timestamp:
03/24/08 03:27:57 (20 months ago)
Author:
takayama
Message:

Implemented fbz:68986
* Implemented UI for session cache
* Implemented php side

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-32/lib/MT/Template/ContextHandlers.pm

    r1537 r1554  
    22842284        && ($arg->{ssi} || $tmpl->include_with_ssi) ? 1 : 0; 
    22852285 
    2286     # If option provided, read from cache 
    2287     my $cache_key = $arg->{key}; 
    2288     my $ttl       = $arg->{ttl} || 0; 
    2289     if ($cache_key) { 
    2290         require MT::Session; 
    2291         my $terms = { id => $cache_key, kind => 'CO' }; 
    2292         my $cache = $ttl ? MT::Session::get_unexpired_value($ttl, $terms) 
    2293                   :        MT::Session->load($terms) 
    2294                   ; 
    2295         if ($cache) { 
    2296             return $cache->data() if !$use_ssi; 
    2297  
    2298             my $include_name = $cache_key || $tmpl_name; 
     2286    # Try to read from cache 
     2287    my $cache_enabled = $blog && $blog->include_cache 
     2288        && ($arg->{cache} || $arg->{key} || (exists $arg->{ttl})) ? 1 : 0; 
     2289    my $cache_key = $arg->{key} ? $arg->{key} 
     2290        : 'blog::' . $blog_id . '::template_' . $type  . '::' . $tmpl_name; 
     2291    my $ttl       = exists $arg->{ttl} ? $arg->{ttl} : 60 * 60; # default 60 min. 
     2292    my $cache_driver; 
     2293    if ($cache_enabled) { 
     2294        require MT::Cache::Negotiate; 
     2295        $cache_driver = MT::Cache::Negotiate->new( ttl => $ttl ); 
     2296        my $cache_value = $cache_driver->get($cache_key); 
     2297 
     2298       if ($cache_value) { 
     2299            return $cache_value if !$use_ssi; 
     2300 
     2301            my $include_name = $arg->{key} || $tmpl_name; 
    22992302            # The template may still be cached from before we were using SSI 
    23002303            # for this template, so check that it's also on disk. 
     
    23252328    } 
    23262329 
    2327     if ($cache_key) { 
    2328         my $cache = MT::Session->load({ 
    2329             id   => $cache_key, 
    2330             kind => 'CO', 
    2331         }); 
    2332         $cache->remove() if $cache; 
    2333         $cache = MT::Session->new; 
    2334         $cache->set_values({ 
    2335             id    => $cache_key, 
    2336             kind  => 'CO', 
    2337             start => time, 
    2338             data  => $ret, 
    2339         }); 
    2340         $cache->save(); 
     2330    if ($cache_enabled) { 
     2331        $cache_driver->replace($cache_key, $ret, $ttl); 
    23412332    } 
    23422333