Source for file view.php

Documentation is available at view.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Cache
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Joomla! Cache view type object
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Cache
  17.  * @since       11.1
  18.  */
  19. {
  20.     /**
  21.      * Get the cached view data
  22.      *
  23.      * @param   object   &$view       The view object to cache output for
  24.      * @param   string   $method      The method name of the view method to cache output for
  25.      * @param   string   $id          The cache data id
  26.      * @param   boolean  $wrkarounds  True to enable workarounds.
  27.      *
  28.      * @return  boolean  True if the cache is hit (false else)
  29.      *
  30.      * @since   11.1
  31.      */
  32.     public function get$view$method 'display' $id false$wrkarounds true )
  33.     {
  34.         // If an id is not given generate it from the request
  35.         if ($id == false)
  36.         {
  37.             $id $this->_makeId($view$method);
  38.         }
  39.  
  40.         $data $this->cache->get($id);
  41.  
  42.         $locktest new stdClass;
  43.         $locktest->locked null;
  44.         $locktest->locklooped null;
  45.  
  46.         if ($data === false)
  47.         {
  48.             $locktest $this->cache->lock($idnull);
  49.  
  50.             // If the loop is completed and returned true it means the lock has been set.
  51.             // If looped is true try to get the cached data again; it could exist now.
  52.             if ($locktest->locked == true && $locktest->locklooped == true)
  53.             {
  54.                 $data $this->cache->get($id);
  55.             }
  56.  
  57.             // False means that locking is either turned off or maxtime has been exceeded.
  58.             // Execute the view.
  59.         }
  60.  
  61.         if ($data !== false)
  62.         {
  63.             $data unserialize(trim($data));
  64.  
  65.             if ($wrkarounds === true)
  66.             {
  67.                 echo JCache::getWorkarounds($data);
  68.             }
  69.             else
  70.             {
  71.                 // No workarounds, so all data is stored in one piece
  72.                 echo (isset($data)) $data null;
  73.             }
  74.  
  75.             if ($locktest->locked == true)
  76.             {
  77.                 $this->cache->unlock($id);
  78.             }
  79.  
  80.             return true;
  81.         }
  82.  
  83.         /*
  84.          * No hit so we have to execute the view
  85.          */
  86.         if (method_exists($view$method))
  87.         {
  88.             // If previous lock failed try again
  89.             if ($locktest->locked == false)
  90.             {
  91.                 $locktest $this->cache->lock($id);
  92.             }
  93.  
  94.             // Capture and echo output
  95.             ob_start();
  96.             ob_implicit_flush(false);
  97.             $view->$method();
  98.             $data ob_get_contents();
  99.             ob_end_clean();
  100.             echo $data;
  101.  
  102.             /*
  103.              * For a view we have a special case.  We need to cache not only the output from the view, but the state
  104.              * of the document head after the view has been rendered.  This will allow us to properly cache any attached
  105.              * scripts or stylesheets or links or any other modifications that the view has made to the document object
  106.              */
  107.             $cached $wrkarounds == true JCache::setWorkarounds($data$data;
  108.  
  109.             // Store the cache data
  110.             $this->cache->store(serialize($cached)$id);
  111.  
  112.             if ($locktest->locked == true)
  113.             {
  114.                 $this->cache->unlock($id);
  115.             }
  116.         }
  117.         return false;
  118.     }
  119.  
  120.     /**
  121.      * Generate a view cache id.
  122.      *
  123.      * @param   object  &$view   The view object to cache output for
  124.      * @param   string  $method  The method name to cache for the view object
  125.      *
  126.      * @return  string  MD5 Hash : view cache id
  127.      *
  128.      * @since   11.1
  129.      */
  130.     protected function _makeId(&$view$method)
  131.     {
  132.         return md5(serialize(array(JCache::makeId()get_class($view)$method)));
  133.     }
  134. }

Documentation generated on Tue, 19 Nov 2013 15:18:12 +0100 by phpDocumentor 1.4.3