Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Cache_Lite

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 /pear/cache/lite/File.php

Documentation is available at File.php

  1. <?php
  2.  
  3. /**
  4. * This class extends Cache_Lite and offers a cache system driven by a master file
  5. *
  6. * With this class, cache validity is only dependent of a given file. Cache files
  7. * are valid only if they are older than the master file. It's a perfect way for
  8. * caching templates results (if the template file is newer than the cache, cache
  9. * must be rebuild...) or for config classes...
  10. * There are some examples in the 'docs/examples' file
  11. * Technical choices are described in the 'docs/technical' file
  12. *
  13. @package Cache_Lite
  14. @version $Id: File.php,v 1.3 2005/12/04 16:03:55 fab Exp $
  15. @author Fabien MARTY <[email protected]>
  16. */
  17.  
  18. // Check to ensure this file is within the rest of the framework
  19. defined('JPATH_BASE'or die();
  20.  
  21. //require_once('Cache/Lite.php');
  22. jimport('pear.cache.Lite');
  23.  
  24. class Cache_Lite_File extends Cache_Lite
  25. {
  26.  
  27.     // --- Private properties ---
  28.  
  29.     
  30.     /**
  31.     * Complete path of the file used for controlling the cache lifetime
  32.     *
  33.     * @var string $_masterFile 
  34.     */
  35.     var $_masterFile = '';
  36.  
  37.     /**
  38.     * Masterfile mtime
  39.     *
  40.     * @var int $_masterFile_mtime 
  41.     */
  42.     var $_masterFile_mtime = 0;
  43.  
  44.     // --- Public methods ----
  45.  
  46.     
  47.     /**
  48.     * Constructor
  49.     *
  50.     * $options is an assoc. To have a look at availables options,
  51.     * see the constructor of the Cache_Lite class in 'Cache_Lite.php'
  52.     *
  53.     * Comparing to Cache_Lite constructor, there is another option :
  54.     * $options = array(
  55.     *     (...) see Cache_Lite constructor
  56.     *     'masterFile' => complete path of the file used for controlling the cache lifetime(string)
  57.     * );
  58.     *
  59.     * @param array $options options
  60.     * @access public
  61.     */
  62.     function Cache_Lite_File($options array(NULL))
  63.     {
  64.         $options['lifetime'0;
  65.         $this->Cache_Lite($options);
  66.         if (isset($options['masterFile'])) {
  67.             $this->_masterFile = $options['masterFile'];
  68.         else {
  69.             return $this->raiseError('Cache_Lite_File : masterFile option must be set !');
  70.         }
  71.         if (!($this->_masterFile_mtime = @filemtime($this->_masterFile))) {
  72.             return $this->raiseError('Cache_Lite_File : Unable to read masterFile : '.$this->_masterFile-3);
  73.         }
  74.     }
  75.  
  76.     /**
  77.     * Test if a cache is available and (if yes) return it
  78.     *
  79.     * @param string $id cache id
  80.     * @param string $group name of the cache group
  81.     * @return string data of the cache (or false if no cache available)
  82.     * @access public
  83.     */
  84.     function get($id$group 'default')
  85.     {
  86.         if ($data parent::get($id$grouptrue)) {
  87.             if ($filemtime $this->lastModified()) {
  88.                 if ($filemtime $this->_masterFile_mtime{
  89.                     return $data;
  90.                 }
  91.             }
  92.         }
  93.         return false;
  94.     }
  95.  
  96. }
  97.  
  98. ?>

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