Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: patTemplate

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 /pattemplate/patTemplate/TemplateCache/File.php

Documentation is available at File.php

  1. <?PHP
  2. /**
  3.  * patTemplate Template cache that stores data on filesystem
  4.  *
  5.  * $Id: File.php 47 2005-09-15 02:55:27Z rhuk $
  6.  *
  7.  * @package        patTemplate
  8.  * @subpackage    Caches
  9.  * @author        Stephan Schmidt <[email protected]>
  10.  */
  11.  
  12. // Check to ensure this file is within the rest of the framework
  13. defined('JPATH_BASE'or die();
  14.  
  15. /**
  16.  * patTemplate Template cache that stores data on filesystem
  17.  *
  18.  * $Id: File.php 47 2005-09-15 02:55:27Z rhuk $
  19.  *
  20.  * Possible parameters for the cache are:
  21.  * - cacheFolder : set the folder from which to load the cache
  22.  * - lifetime : seconds for which the cache is valid, if set to auto, it will check
  23.  *   whether the cache is older than the original file (if the reader supports this)
  24.  * - prefix for the filenames
  25.  *
  26.  * @package        patTemplate
  27.  * @subpackage    Caches
  28.  * @author        Stephan Schmidt <[email protected]>
  29.  */
  30. {
  31.    /**
  32.     * parameters of the cache
  33.     *
  34.     * @access    private
  35.     * @var        array 
  36.     */
  37.     var $_params = array(
  38.                          'cacheFolder' => './cache',
  39.                          'lifetime'       => 'auto',
  40.                          'prefix'       => '',
  41.                          'filemode'    => null
  42.                         );
  43.  
  44.  
  45.    /**
  46.     * load template from cache
  47.     *
  48.     * @access    public
  49.     * @param    string            cache key
  50.     * @param    integer            modification time of original template
  51.     * @return    array|boolean   either an array containing the templates or false cache could not be loaded
  52.     */
  53.     function load($key$modTime = -1)
  54.     {
  55.         $filename $this->_getCachefileName$key );
  56.         if (!file_exists($filename|| !is_readable($filename)) {
  57.             return false;
  58.         }
  59.  
  60.         $generatedOn filemtime$filename );
  61.         $ttl         $this->getParam('lifetime');
  62.         if ($ttl == 'auto'{
  63.             if ($modTime 1{
  64.                 return false;
  65.             }
  66.             if ($modTime $generatedOn{
  67.                 return false;
  68.             }
  69.             return unserialize(file_get_contents($filename));
  70.         elseif(is_int$ttl)) {
  71.             if ($generatedOn $ttl time()) {
  72.                 return false;
  73.             }
  74.             return unserializefile_get_contents$filename ) );
  75.         }
  76.  
  77.         return false;
  78.     }
  79.  
  80.    /**
  81.     * write template to cache
  82.     *
  83.     * @access    public
  84.     * @param    string        cache key
  85.     * @param    array        templates to store
  86.     * @return    boolean        true on success
  87.     */
  88.     function write$key$templates )
  89.     {
  90.         $cacheFile $this->_getCachefileName($key);
  91.         $fp @fopen($cacheFile'w');
  92.         if (!$fp{
  93.             return false;
  94.         }
  95.         flock$fpLOCK_EX );
  96.         fputs$fpserialize($templates));
  97.         flock$fpLOCK_UN );
  98.         $filemode $this->getParam('filemode');
  99.         if ($filemode !== null{
  100.             chmod($cacheFile$filemode);
  101.         }
  102.         return true;
  103.     }
  104.  
  105.    /**
  106.     * get the cache filename
  107.     *
  108.     * @access    private
  109.     * @param    string        cache key
  110.     * @return    string        cache file name
  111.     */
  112.     function _getCachefileName$key )
  113.     {
  114.         return $this->getParam'cacheFolder' '/' $this->getParam'prefix' ).$key '.cache';
  115.     }
  116. }
  117. ?>

Documentation generated on Mon, 05 Mar 2007 20:58:39 +0000 by phpDocumentor 1.3.1