Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Wednesday, October 14, 2026

Diff for Metafox/lib/Cache/Lite.php between version 1.1 and 1.2

version 1.1, 2005/06/05 12:14:00 version 1.2, 2005/11/07 20:37:18
Line 10 
Line 10 
 * There are some examples in the 'docs/examples' file  * There are some examples in the 'docs/examples' file
 * Technical choices are described in the 'docs/technical' file  * Technical choices are described in the 'docs/technical' file
 *  *
 * A tutorial is available in english at this url :  
 * http://www.pearfr.org/index.php/en/article/cache_lite  
 * (big thanks to Pierre-Alain Joye for the translation)  
 *  
 * The same tutorial is also available in french at this url :  
 * http://www.pearfr.org/index.php/fr/article/cache_lite  
 *  
 * Memory Caching is from an original idea of  * Memory Caching is from an original idea of
 * Mike BENOIT <ipso@snappymail.ca>  * Mike BENOIT <ipso@snappymail.ca>
 *  *
   * Nota : A chinese documentation (thanks to RainX <china_1982@163.com>) is
   * available at :
   * http://rainx.phpmore.com/manual/cache_lite.html
   *
 * @package Cache_Lite  * @package Cache_Lite
 * @category Caching  * @category Caching
 * @version $Id$  * @version $Id$
Line 220  class Cache_Lite
Line 217  class Cache_Lite
     /**      /**
     * Nested directory level      * Nested directory level
     *      *
       * Set the hashed directory structure level. 0 means "no hashed directory
       * structure", 1 means "one level of directory", 2 means "two levels"...
       * This option can speed up Cache_Lite only when you have many thousands of
       * cache file. Only specific benchs can help you to choose the perfect value
       * for you. Maybe, 1 or 2 is a good start.
     *      *
     * @var int $_hashedDirectoryLevel      * @var int $_hashedDirectoryLevel
     */      */
     var $_hashedDirectoryLevel = 0;      var $_hashedDirectoryLevel = 0;
   
       /**
       * Umask for hashed directory structure
       *
       * @var int $_hashedDirectoryUmask
       */
       var $_hashedDirectoryUmask = 0700;
   
     // --- Public methods ---      // --- Public methods ---
   
     /**      /**
Line 247  class Cache_Lite
Line 256  class Cache_Lite
     *     'automaticSerialization' => enable / disable automatic serialization (boolean)      *     'automaticSerialization' => enable / disable automatic serialization (boolean)
     *     'automaticCleaningFactor' => distable / tune automatic cleaning process (int)      *     'automaticCleaningFactor' => distable / tune automatic cleaning process (int)
     *     'hashedDirectoryLevel' => level of the hashed directory system (int)      *     'hashedDirectoryLevel' => level of the hashed directory system (int)
       *     'hashedDirectoryUmask' => umask for hashed directory structure (int)
     * );      * );
     *      *
     * @param array $options options      * @param array $options options
Line 254  class Cache_Lite
Line 264  class Cache_Lite
     */      */
     function Cache_Lite($options = array(NULL))      function Cache_Lite($options = array(NULL))
     {      {
         $availableOptions = array('hashedDirectoryLevel', 'automaticCleaningFactor', 'automaticSerialization', 'fileNameProtection', 'memoryCaching', 'onlyMemoryCaching', 'memoryCachingLimit', 'cacheDir', 'caching', 'lifeTime', 'fileLocking', 'writeControl', 'readControl', 'readControlType', 'pearErrorMode');          $availableOptions = array('hashedDirectoryUmask', 'hashedDirectoryLevel', 'automaticCleaningFactor', 'automaticSerialization', 'fileNameProtection', 'memoryCaching', 'onlyMemoryCaching', 'memoryCachingLimit', 'cacheDir', 'caching', 'lifeTime', 'fileLocking', 'writeControl', 'readControl', 'readControlType', 'pearErrorMode');
         foreach($options as $key => $value) {          foreach($options as $key => $value) {
             if(in_array($key, $availableOptions)) {              if(in_array($key, $availableOptions)) {
                 $property = '_'.$key;                  $property = '_'.$key;
Line 387  class Cache_Lite
Line 397  class Cache_Lite
     * else only cache files of the specified group will be destroyed      * else only cache files of the specified group will be destroyed
     *      *
     * @param string $group name of the cache group      * @param string $group name of the cache group
     * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup'      * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup',
       *                                        'callback_myFunction'
     * @return boolean true if no problem      * @return boolean true if no problem
     * @access public      * @access public
     */      */
Line 467  class Cache_Lite
Line 478  class Cache_Lite
     * @return int last modification time      * @return int last modification time
     */      */
     function lastModified() {      function lastModified() {
         return filemtime($this->_file);          return @filemtime($this->_file);
     }      }
   
     /**      /**
Line 511  class Cache_Lite
Line 522  class Cache_Lite
     *      *
     * @param string $dir directory complete path (with a trailing slash)      * @param string $dir directory complete path (with a trailing slash)
     * @param string $group name of the cache group      * @param string $group name of the cache group
     * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup'      * @param string $mode flush cache mode : 'old', 'ingroup', 'notingroup',
                                                'callback_myFunction'
     * @return boolean true if no problem      * @return boolean true if no problem
     * @access private      * @access private
     */      */
Line 543  class Cache_Lite
Line 555  class Cache_Lite
                 if (substr($file, 0, 6)=='cache_') {                  if (substr($file, 0, 6)=='cache_') {
                     $file2 = $dir . $file;                      $file2 = $dir . $file;
                     if (is_file($file2)) {                      if (is_file($file2)) {
                         switch ($mode) {                          switch (substr($mode, 0, 9)) {
                             case 'old':                              case 'old':
                                 // files older than lifeTime get deleted from cache                                  // files older than lifeTime get deleted from cache
                                 if ((mktime() - filemtime($file2)) > $this->_lifeTime) {                                  if ((mktime() - filemtime($file2)) > $this->_lifeTime) {
                                     $result = ($result and ($this->_unlink($file2)));                                      $result = ($result and ($this->_unlink($file2)));
                                 }                                  }
                                 break;                                  break;
                             case 'notingroup':                              case 'notingrou':
                                 if (!strpos($file2, $motif, 0)) {                                  if (!strpos($file2, $motif, 0)) {
                                     $result = ($result and ($this->_unlink($file2)));                                      $result = ($result and ($this->_unlink($file2)));
                                 }                                  }
                                 break;                                  break;
                               case 'callback_':
                                   $func = substr($mode, 9, strlen($mode) - 9);
                                   if ($func($file2, $group)) {
                                       $result = ($result and ($this->_unlink($file2)));
                                   }
                                   break;
                             case 'ingroup':                              case 'ingroup':
                             default:                              default:
                                 if (strpos($file2, $motif, 0)) {                                  if (strpos($file2, $motif, 0)) {
Line 635  class Cache_Lite
Line 653  class Cache_Lite
                 $hashControl = @fread($fp, 32);                  $hashControl = @fread($fp, 32);
                 $length = $length - 32;                  $length = $length - 32;
             }              }
             $data = @fread($fp, $length);              if ($length) {
                   $data = @fread($fp, $length);
               } else {
                   $data = '';
               }
             set_magic_quotes_runtime($mqr);              set_magic_quotes_runtime($mqr);
             if ($this->_fileLocking) @flock($fp, LOCK_UN);              if ($this->_fileLocking) @flock($fp, LOCK_UN);
             @fclose($fp);              @fclose($fp);
Line 680  class Cache_Lite
Line 702  class Cache_Lite
                     $root = $this->_cacheDir;                      $root = $this->_cacheDir;
                     for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {                      for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {
                         $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';                          $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';
                         @mkdir($root, 0700);                          @mkdir($root, $this->_hashedDirectoryUmask);
                     }                      }
                     $try = 2;                      $try = 2;
                 } else {                  } else {

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top