[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/cache/handler/ -> page.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: page.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla.Framework
   5  * @subpackage    Cache
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  /**
  19   * Joomla! Cache page type object
  20   *
  21   * @package        Joomla.Framework
  22   * @subpackage    Cache
  23   * @since        1.5
  24   */
  25  class JCachePage extends JCache
  26  {
  27      /**
  28       * Get the cached page data
  29       *
  30       * @access    public
  31       * @param    string    $id        The cache data id
  32       * @param    string    $group    The cache data group
  33       * @return    boolean    True if the cache is hit (false else)
  34       * @since    1.5
  35       */
  36  	function get( $id=false, $group='page' )
  37      {
  38          // Initialize variables
  39          $data = false;
  40  
  41          // If an id is not given generate it from the request
  42          if ($id == false) {
  43              $id = $this->_makeId();
  44          }
  45  
  46  
  47          // If the etag matches the page id ... sent a no change header and exit : utilize browser cache
  48          if ( !headers_sent() && isset($_SERVER['HTTP_IF_NONE_MATCH']) ){
  49              $etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
  50              if( $etag == $id) {
  51                  $browserCache = isset($this->_options['browsercache']) ? $this->_options['browsercache'] : false;
  52                  if ($browserCache) {
  53                      $this->_noChange();
  54                  }
  55              }
  56          }
  57  
  58          // We got a cache hit... set the etag header and echo the page data
  59          $data = parent::get($id, $group);
  60          if ($data !== false) {
  61              $this->_setEtag($id);
  62              return $data;
  63          }
  64  
  65          // Set id and group placeholders
  66          $this->_id        = $id;
  67          $this->_group    = $group;
  68          return false;
  69      }
  70  
  71      /**
  72       * Stop the cache buffer and store the cached data
  73       *
  74       * @access    public
  75       * @return    boolean    True if cache stored
  76       * @since    1.5
  77       */
  78  	function store()
  79      {
  80          // Get page data from JResponse body
  81          $data = JResponse::getBody();
  82  
  83          // Get id and group and reset them placeholders
  84          $id        = $this->_id;
  85          $group    = $this->_group;
  86          $this->_id        = null;
  87          $this->_group    = null;
  88  
  89          // Only attempt to store if page data exists
  90          if ($data) {
  91              return parent::store($data, $id, $group);
  92          }
  93          return false;
  94      }
  95  
  96      /**
  97       * Generate a page cache id
  98       * @todo    Discuss whether this should be coupled to a data hash or a request hash ... perhaps hashed with a serialized request
  99       *
 100       * @access    private
 101       * @return    string    MD5 Hash : page cache id
 102       * @since    1.5
 103       */
 104  	function _makeId()
 105      {
 106          return md5(JRequest::getURI());
 107      }
 108  
 109      /**
 110       * There is no change in page data so send a not modified header and die gracefully
 111       *
 112       * @access    private
 113       * @return    void
 114       * @since    1.5
 115       */
 116  	function _noChange()
 117      {
 118          global $mainframe;
 119  
 120          // Send not modified header and exit gracefully
 121          header( 'HTTP/1.x 304 Not Modified', true );
 122          $mainframe->close();
 123      }
 124  
 125      /**
 126       * Set the ETag header in the response
 127       *
 128       * @access    private
 129       * @return    void
 130       * @since    1.5
 131       */
 132  	function _setEtag($etag)
 133      {
 134          JResponse::setHeader( 'ETag', $etag, true );
 135      }
 136  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1