Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/cache/handlers/page.php

Documentation is available at page.php

  1. <?php
  2. /**
  3. @version        $Id: page.php 6691 2007-02-21 10:00:43Z louis $
  4. @package        Joomla.Framework
  5. @subpackage    Cache
  6. @copyright    Copyright (C) 2005 - 2007 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.  * @author        Johan Janssens <[email protected]>
  22.  * @author        Louis Landry <[email protected]>
  23.  * @package        Joomla.Framework
  24.  * @subpackage    Cache
  25.  * @since        1.5
  26.  */
  27. class JCachePage extends JCache
  28. {
  29.     /**
  30.      * Get the cached page data
  31.      *
  32.      * @access    public
  33.      * @param    string    $id        The cache data id
  34.      * @param    string    $group    The cache data group
  35.      * @return    boolean    True if the cache is hit (false else)
  36.      * @since    1.5
  37.      */
  38.     function get$id=false$group='page' )
  39.     {
  40.         // Initialize variables
  41.         $data false;
  42.  
  43.         // If an id is not given generate it from the request
  44.         if ($id == false{
  45.             $id $this->_makeId();
  46.         }
  47.  
  48.  
  49.         // If the etag matches the page id ... sent a no change header and exit : utilize browser cache
  50.         if !headers_sent(&& isset($_SERVER['HTTP_IF_NONE_MATCH']) ){
  51.             $etag stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
  52.             if$etag == $id{
  53.                 $browserCache = isset($this->_options['browsercache']$this->_options['browsercache'false;
  54.                 if ($browserCache{
  55.                     $this->_noChange();
  56.                 }
  57.             }
  58.         }
  59.  
  60.         // We got a cache hit... set the etag header and echo the page data
  61.         $data parent::get($id$group);
  62.         if ($data !== false{
  63.             $this->_setEtag($id);
  64.             return $data;
  65.         }
  66.  
  67.         // Set id and group placeholders
  68.         $this->_id        $id;
  69.         $this->_group    $group;
  70.         return false;
  71.     }
  72.  
  73.     /**
  74.      * Stop the cache buffer and store the cached data
  75.      *
  76.      * @access    public
  77.      * @return    boolean    True if cache stored
  78.      * @since    1.5
  79.      */
  80.     function store()
  81.     {
  82.         // Get page data from JResponse body
  83.         $data JResponse::getBody();
  84.  
  85.         // Get id and group and reset them placeholders
  86.         $id        $this->_id;
  87.         $group    $this->_group;
  88.         $this->_id        null;
  89.         $this->_group    null;
  90.  
  91.         // Only attempt to store if page data exists
  92.         if ($data{
  93.             return parent::store($data$id$group);
  94.         }
  95.         return false;
  96.     }
  97.  
  98.     /**
  99.      * Generate a page cache id
  100.      * @todo    Discuss whether this should be coupled to a data hash or a request hash ... perhaps hashed with a serialized request
  101.      *
  102.      * @access    private
  103.      * @return    string    MD5 Hash : page cache id
  104.      * @since    1.5
  105.      */
  106.     function _makeId()
  107.     {
  108.         return md5(JRequest::getURI());
  109.     }
  110.  
  111.     /**
  112.      * There is no change in page data so send a not modified header and die gracefully
  113.      *
  114.      * @access    private
  115.      * @return    void 
  116.      * @since    1.5
  117.      */
  118.     function _noChange()
  119.     {
  120.         global $mainframe;
  121.  
  122.         // Send not modified header and exit gracefully
  123.         header'HTTP/1.x 304 Not Modified'true );
  124.         $mainframe->close();
  125.     }
  126.  
  127.     /**
  128.      * Set the ETag header in the response
  129.      *
  130.      * @access    private
  131.      * @return    void 
  132.      * @since    1.5
  133.      */
  134.     function _setEtag($etag)
  135.     {
  136.         JResponse::setHeader'ETag'$etagtrue );
  137.     }
  138. }
  139. ?>

Documentation generated on Mon, 05 Mar 2007 21:12:34 +0000 by phpDocumentor 1.3.1