Development

Changeset 24554

You must first sign up to be able to contribute.

Changeset 24554

Show
Ignore:
Timestamp:
11/30/09 11:24:36 (5 years ago)
Author:
fabien
Message:

[sfSuperCachePlugin] backported some changesets from 1.0 (closes #6765)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSuperCachePlugin/branches/1.3/lib/sfSuperCacheFilter.class.php

    r24553 r24554  
    2727    // execute this filter only if cache is set and no GET or POST parameters 
    2828    // execute this filter not in debug mode, only if no_script_name and for 200 response code 
    29     if ( !sfConfig::get('sf_cache') || count($_GET) || count($_POST) || sfConfig::get('sf_debug') || 
    30          !sfConfig::get('sf_no_script_name') || $response->getStatusCode() != 200 ) 
     29    if ( 
     30      (!sfConfig::get('sf_cache') || count($_GET) || count($_POST)) 
     31      || 
     32      (sfConfig::get('sf_debug') || !sfConfig::get('sf_no_script_name') || $response->getStatusCode() != 200) 
     33    ) 
    3134    { 
    3235      return; 
     
    3639    $cacheManager = $this->getContext()->getViewCacheManager(); 
    3740    $uri = $this->getContext()->getRouting()->getCurrentInternalUri(); 
    38  
    3941    if ($cacheManager->isCacheable($uri) && $cacheManager->withLayout($uri)) 
    4042    { 
     
    6264      if (!is_dir($file)) 
    6365      { 
     66        $response = $this->getContext()->getResponse(); 
     67 
    6468        $expiryDate = time() + $cacheManager->getLifetime($uri); 
    6569        // Note: some proxies do cache 302 responses, despite the rfc, so we explicitely ask for no cache 
    66         $header = $this->getParameter('check_lifetime', true) ? "<?php if (time() > $expiryDate) { unlink(__FILE__); header('Pragma: no-cache'); header('Location: '.\$_SERVER['REQUEST_URI']);  exit; } ?>\n" : ''; 
    67         file_put_contents($file, $header . $this->getContext()->getResponse()->getContent()); 
     70        if ($this->getParameter('check_lifetime', true)) 
     71        { 
     72          $header = sprintf("<?php if (time() > %d) { unlink(__FILE__); header('Pragma: no-cache'); header('Location: '.\$_SERVER['REQUEST_URI']);  exit; } ?>\n", $expiryDate); 
     73          $header .= sprintf("<?php header('Content-Type: %s') ?>\n", $response->getContentType()); 
     74          foreach(array('Cache-Control', 'Pragma', 'Expires') as $key) 
     75          { 
     76            if ($value = $response->getHttpHeader($key)) 
     77            { 
     78              $header .= sprintf("<?php header('%s: %s') ?>\n", $key, $value); 
     79            } 
     80          } 
     81        } 
     82        else 
     83        { 
     84          $header = ''; 
     85        } 
     86        file_put_contents($file, $header.$response->getContent()); 
    6887        chmod($file, 0666); 
    6988      } 
    7089      umask($current_umask); 
    7190    } 
    72     else 
    73     { 
    74     } 
    7591  } 
    7692}