Show
Ignore:
Timestamp:
04/17/08 13:11:31 (20 months ago)
Author:
takayama
Message:

Fixed BugId:75137
* Changed to using cache_key for include cache directory

Files:
1 modified

Legend:

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

    r1926 r1949  
    23282328    my $blog = $ctx->stash('blog') || MT->model('blog')->load($blog_id); 
    23292329 
     2330    my %include_recipe; 
    23302331    my $use_ssi = $blog && $blog->include_system 
    23312332        && ($arg->{ssi} || $tmpl->include_with_ssi) ? 1 : 0; 
     
    23342335        # easiest way to determine this is from the variable 
    23352336        # space setting. 
    2336         $use_ssi = 0 if $ctx->var('system_template'); 
     2337        if ($ctx->var('system_template')) { 
     2338            $use_ssi = 0; 
     2339        } else { 
     2340            my $extra_path = $arg->{cache_key} ? $arg->{cache_key} 
     2341                : $tmpl->cache_path ? $tmpl->cache_path 
     2342                    : ''; 
     2343           %include_recipe = ( 
     2344                name => $tmpl_name, 
     2345                id   => $tmpl->id, 
     2346                path => $extra_path, 
     2347            ); 
     2348        } 
    23372349    } 
    23382350 
     
    23422354      && $blog->include_cache 
    23432355      && ( ( $arg->{cache} && $arg->{cache} > 0 ) 
    2344         || $arg->{key} 
     2356        || $arg->{cache_key} 
    23452357        || ( exists $arg->{ttl} ) 
    23462358        || $tmpl->use_cache ) ? 1 : 0; 
    23472359    my $cache_key = 
    2348         $arg->{key} 
    2349       ? $arg->{key} 
     2360        $arg->{cache_key} 
     2361      ? $arg->{cache_key} 
    23502362      : 'blog::' . $blog_id . '::template_' . $type . '::' . $tmpl_name; 
    23512363    my $ttl = 
     
    23622374                if ($use_ssi) { 
    23632375                    # base cache expiration on physical file timestamp 
    2364                     my $include_name = $arg->{key} || $tmpl_name; 
    2365                     my $mtime = (stat($blog->include_path($include_name)))[9]; 
     2376                    my $include_file = $blog->include_path(\%include_recipe); 
     2377                    my $mtime = (stat($include_file))[9]; 
    23662378                    if ($mtime && (MT::Util::ts2epoch(undef, $latest) > $mtime ) ) { 
    23672379                        $ttl = 1; # bound to force an update 
     
    23882400            return $cache_value if !$use_ssi; 
    23892401 
    2390             my $include_name = $arg->{key} || $tmpl_name; 
    23912402            # The template may still be cached from before we were using SSI 
    23922403            # for this template, so check that it's also on disk. 
    2393             my ($path, $file_path) = $blog->include_path($include_name); 
    2394             if ($blog->file_mgr->exists($file_path)) { 
    2395                 return $blog->include_statement($include_name); 
     2404            my $include_file = $blog->include_path(\%include_recipe); 
     2405            if ($blog->file_mgr->exists($include_file)) { 
     2406                return $blog->include_statement(\%include_recipe); 
    23962407            } 
    23972408        } 
     
    24242435 
    24252436    if ($use_ssi) { 
    2426         my $include_name = $arg->{key} || $tmpl_name; 
     2437        my ($include_file, $path, $filename) = 
     2438            $blog->include_path(\%include_recipe); 
    24272439        my $fmgr = $blog->file_mgr; 
    2428         my ($path, $file_path) = $blog->include_path($include_name); 
    24292440        if (!$fmgr->exists($path)) { 
    24302441            if (!$fmgr->mkpath($path)) { 
     
    24332444            } 
    24342445        } 
    2435         defined($fmgr->put_data($ret, $file_path)) 
     2446        defined($fmgr->put_data($ret, $include_file)) 
    24362447            or return $ctx->error(MT->translate("Writing to '[_1]' failed: [_2]", 
    2437                 $file_path, $fmgr->errstr)); 
     2448                $include_file, $fmgr->errstr)); 
    24382449 
    24392450        MT->upload_file_to_sync( 
    2440             url  => $blog->include_url($include_name), 
    2441             file => $file_path, 
     2451            url  => $blog->include_url(\%include_recipe), 
     2452            file => $include_file, 
    24422453            blog => $blog, 
    24432454        ); 
    24442455 
    2445         return $blog->include_statement($include_name); 
     2456        my $stat = $blog->include_statement(\%include_recipe); 
     2457        return $stat; 
    24462458    } 
    24472459