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/view.php

Documentation is available at view.php

  1. <?php
  2. /**
  3. @version        $Id: view.php 6472 2007-02-03 10:47:26Z pasamio $
  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 view type object
  20.  *
  21.  * @author        Louis Landry <[email protected]>
  22.  * @package        Joomla.Framework
  23.  * @subpackage    Cache
  24.  * @since        1.5
  25.  */
  26. class JCacheView extends JCache
  27. {
  28.     /**
  29.      * Get the cached view data
  30.      *
  31.      * @access    public
  32.      * @param    object    $view    The view object to cache output for
  33.      * @param    string    $method    The method name of the view method to cache output for
  34.      * @param    string    $group    The cache data group
  35.      * @param    string    $id        The cache data id
  36.      * @return    boolean    True if the cache is hit (false else)
  37.      * @since    1.5
  38.      */
  39.     function get&$view$method$group='view'$id=false )
  40.     {
  41.         // Initialize variables
  42.         $data false;
  43.  
  44.         // If an id is not given generate it from the request
  45.         if ($id == false{
  46.             $id $this->_makeId($view$method);
  47.         }
  48.  
  49.         $data parent::get($id$group);
  50.         if ($data !== false{
  51.             $data unserialize($data);
  52.             $document =JFactory::getDocument();
  53.             $document->setHeadData((isset($data['head'])) $data['head'array());
  54.             echo (isset($data['body'])) $data['body'null;
  55.             return true;
  56.         }
  57.  
  58.         /*
  59.          * No hit so we have to execute the view
  60.          */
  61.         if (method_exists($view$method)) {
  62.             // Capture and echo output
  63.             ob_start();
  64.             ob_implicit_flushfalse );
  65.             $view->$method();
  66.             $data ob_get_contents();
  67.             ob_end_clean();
  68.             echo $data;
  69.  
  70.             /*
  71.              * For a view we have a special case.  We need to cache not only the output from the view, but the state
  72.              * of the document head after the view has been rendered.  This will allow us to properly cache any attached
  73.              * scripts or stylesheets or links or any other modifications that the view has made to the document object
  74.              */
  75.             $cached array();
  76.             // View body data
  77.             $cached['body'$data;
  78.             // Document head data
  79.             $document =JFactory::getDocument();
  80.             $cached['head'$document->getHeadData();
  81.             // Store the cache data
  82.             $this->store(serialize($cached)$id$group);
  83.         }
  84.         return false;
  85.     }
  86.  
  87.     /**
  88.      * Generate a view cache id
  89.      *
  90.      * @access    private
  91.      * @param    object    $view    The view object to cache output for
  92.      * @param    string    $method    The method name to cache for the view object
  93.      * @return    string    MD5 Hash : view cache id
  94.      * @since    1.5
  95.      */
  96.     function _makeId(&$view$method)
  97.     {
  98.         return md5(serialize(array(JRequest::getURI()get_class($view)$method)));
  99.     }
  100. }
  101. ?>

Documentation generated on Mon, 05 Mar 2007 21:31:38 +0000 by phpDocumentor 1.3.1