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.2 and 1.3

version 1.2, 2005/11/07 20:37:18 version 1.3, 2024/11/20 15:48:03
Line 77  class Cache_Lite
Line 77  class Cache_Lite
     * @var string $_file      * @var string $_file
     */      */
     var $_file;      var $_file;
   
     /**      /**
     * File name (without path)      * File name (without path)
     *      *
Line 126  class Cache_Lite
Line 126  class Cache_Lite
     * @var int $_pearErrorMode      * @var int $_pearErrorMode
     */      */
     var $_pearErrorMode = CACHE_LITE_ERROR_RETURN;      var $_pearErrorMode = CACHE_LITE_ERROR_RETURN;
   
     /**      /**
     * Current cache id      * Current cache id
     *      *
Line 144  class Cache_Lite
Line 144  class Cache_Lite
     /**      /**
     * Enable / Disable "Memory Caching"      * Enable / Disable "Memory Caching"
     *      *
     * NB : There is no lifetime for memory caching !      * NB : There is no lifetime for memory caching !
     *      *
     * @var boolean $_memoryCaching      * @var boolean $_memoryCaching
     */      */
Line 178  class Cache_Lite
Line 178  class Cache_Lite
     * @var int $memoryCachingLimit      * @var int $memoryCachingLimit
     */      */
     var $_memoryCachingLimit = 1000;      var $_memoryCachingLimit = 1000;
   
     /**      /**
     * File Name protection      * File Name protection
     *      *
Line 190  class Cache_Lite
Line 190  class Cache_Lite
     * @var boolean $fileNameProtection      * @var boolean $fileNameProtection
     */      */
     var $_fileNameProtection = true;      var $_fileNameProtection = true;
   
     /**      /**
     * Enable / disable automatic serialization      * Enable / disable automatic serialization
     *      *
     * it can be used to save directly datas which aren't strings      * it can be used to save directly datas which aren't strings
     * (but it's slower)      * (but it's slower)
     *      *
     * @var boolean $_serialize      * @var boolean $_serialize
     */      */
     var $_automaticSerialization = false;      var $_automaticSerialization = false;
   
     /**      /**
     * Disable / Tune the automatic cleaning process      * Disable / Tune the automatic cleaning process
     *      *
Line 213  class Cache_Lite
Line 213  class Cache_Lite
     * @var int $_automaticCleaning      * @var int $_automaticCleaning
     */      */
     var $_automaticCleaningFactor = 0;      var $_automaticCleaningFactor = 0;
   
     /**      /**
     * Nested directory level      * Nested directory level
     *      *
     * Set the hashed directory structure level. 0 means "no hashed directory      * Set the hashed directory structure level. 0 means "no hashed directory
     * structure", 1 means "one level of directory", 2 means "two levels"...      * 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      * 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      * cache file. Only specific benchs can help you to choose the perfect value
     * for you. Maybe, 1 or 2 is a good start.      * 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      * Umask for hashed directory structure
     *      *
     * @var int $_hashedDirectoryUmask      * @var int $_hashedDirectoryUmask
     */      */
     var $_hashedDirectoryUmask = 0700;      var $_hashedDirectoryUmask = 0700;
   
     // --- Public methods ---      // --- Public methods ---
   
     /**      /**
Line 273  class Cache_Lite
Line 273  class Cache_Lite
         }          }
         $this->_refreshTime = time() - $this->_lifeTime;          $this->_refreshTime = time() - $this->_lifeTime;
     }      }
   
     /**      /**
     * Test if a cache is available and (if yes) return it      * Test if a cache is available and (if yes) return it
     *      *
Line 322  class Cache_Lite
Line 322  class Cache_Lite
         }          }
         return false;          return false;
     }      }
   
     /**      /**
     * Save some data in a cache file      * Save some data in a cache file
     *      *
Line 397  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'      *                                        'callback_myFunction'
     * @return boolean true if no problem      * @return boolean true if no problem
     * @access public      * @access public
Line 406  class Cache_Lite
Line 406  class Cache_Lite
     {      {
         return $this->_cleanDir($this->_cacheDir, $group, $mode);          return $this->_cleanDir($this->_cacheDir, $group, $mode);
     }      }
   
     /**      /**
     * Set to debug mode      * Set to debug mode
     *      *
Line 469  class Cache_Lite
Line 469  class Cache_Lite
             }              }
         }          }
     }      }
   
     /**      /**
     * Return the cache last modification time      * Return the cache last modification time
     *      *
Line 480  class Cache_Lite
Line 480  class Cache_Lite
     function lastModified() {      function lastModified() {
         return @filemtime($this->_file);          return @filemtime($this->_file);
     }      }
   
     /**      /**
     * Trigger a PEAR error      * Trigger a PEAR error
     *      *
Line 497  class Cache_Lite
Line 497  class Cache_Lite
         include_once('PEAR.php');          include_once('PEAR.php');
         PEAR::raiseError($msg, $code, $this->_pearErrorMode);          PEAR::raiseError($msg, $code, $this->_pearErrorMode);
     }      }
   
     // --- Private methods ---      // --- Private methods ---
   
     /**      /**
     * Remove a file      * Remove a file
     *      *
     * @param string $file complete file path and name      * @param string $file complete file path and name
     * @return boolean true if no problem      * @return boolean true if no problem
     * @access private      * @access private
Line 527  class Cache_Lite
Line 527  class Cache_Lite
     * @return boolean true if no problem      * @return boolean true if no problem
     * @access private      * @access private
     */      */
     function _cleanDir($dir, $group = false, $mode = 'ingroup')      function _cleanDir($dir, $group = false, $mode = 'ingroup')
     {      {
         if ($this->_fileNameProtection) {          if ($this->_fileNameProtection) {
             $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';              $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
Line 535  class Cache_Lite
Line 535  class Cache_Lite
             $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';              $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
         }          }
         if ($this->_memoryCaching) {          if ($this->_memoryCaching) {
             while (list($key, $value) = each($this->_memoryCachingArray)) {                          foreach ($this->_memoryCachingArray as $key => $value) {
                 if (strpos($key, $motif, 0)) {                  if (strpos($key, $motif, 0)) {
                     unset($this->_memoryCachingArray[$key]);                      unset($this->_memoryCachingArray[$key]);
                     $this->_memoryCachingCounter = $this->_memoryCachingCounter - 1;                      $this->_memoryCachingCounter = $this->_memoryCachingCounter - 1;
Line 589  class Cache_Lite
Line 589  class Cache_Lite
         }          }
         return $result;          return $result;
     }      }
   
     /**      /**
     * Add some date in the memory caching array      * Add some date in the memory caching array
     *      *
Line 601  class Cache_Lite
Line 601  class Cache_Lite
     {      {
         $this->_memoryCachingArray[$this->_file] = $data;          $this->_memoryCachingArray[$this->_file] = $data;
         if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {          if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
             list($key, $value) = each($this->_memoryCachingArray);                          foreach ($this->_memoryCachingArray as $key => $value) {
             unset($this->_memoryCachingArray[$key]);                                  unset($this->_memoryCachingArray[$key]);
                                   break;
                           }
         } else {          } else {
             $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;              $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1;
         }          }
Line 617  class Cache_Lite
Line 619  class Cache_Lite
     */      */
     function _setFileName($id, $group)      function _setFileName($id, $group)
     {      {
   
         if ($this->_fileNameProtection) {          if ($this->_fileNameProtection) {
             $suffix = 'cache_'.md5($group).'_'.md5($id);              $suffix = 'cache_'.md5($group).'_'.md5($id);
         } else {          } else {
Line 628  class Cache_Lite
Line 630  class Cache_Lite
             $hash = md5($suffix);              $hash = md5($suffix);
             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) . '/';
             }              }
         }          }
         $this->_fileName = $suffix;          $this->_fileName = $suffix;
         $this->_file = $root.$suffix;          $this->_file = $root.$suffix;
     }      }
   
     /**      /**
     * Read the cache file and return the content      * Read the cache file and return the content
     *      *
Line 652  class Cache_Lite
Line 654  class Cache_Lite
             if ($this->_readControl) {              if ($this->_readControl) {
                 $hashControl = @fread($fp, 32);                  $hashControl = @fread($fp, 32);
                 $length = $length - 32;                  $length = $length - 32;
             }              }
             if ($length) {              if ($length) {
                 $data = @fread($fp, $length);                  $data = @fread($fp, $length);
             } else {              } else {
Line 664  class Cache_Lite
Line 666  class Cache_Lite
             if ($this->_readControl) {              if ($this->_readControl) {
                 $hashData = $this->_hash($data, $this->_readControlType);                  $hashData = $this->_hash($data, $this->_readControlType);
                 if ($hashData != $hashControl) {                  if ($hashData != $hashControl) {
                     @touch($this->_file, time() - 2*abs($this->_lifeTime));                      @touch($this->_file, time() - 2*abs($this->_lifeTime));
                     return false;                      return false;
                 }                  }
             }              }
             return $data;              return $data;
         }          }
         $this->raiseError('Cache_Lite : Unable to read cache !', -2);          $this->raiseError('Cache_Lite : Unable to read cache !', -2);
         return false;          return false;
     }      }
   
     /**      /**
     * Write the given data in the cache file      * Write the given data in the cache file
     *      *
Line 713  class Cache_Lite
Line 715  class Cache_Lite
         $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1);          $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1);
         return false;          return false;
     }      }
   
     /**      /**
     * Write the given data in the cache file and control it just after to avoir corrupted cache entries      * Write the given data in the cache file and control it just after to avoir corrupted cache entries
     *      *
Line 727  class Cache_Lite
Line 729  class Cache_Lite
         $dataRead = $this->_read($data);          $dataRead = $this->_read($data);
         return ($dataRead==$data);          return ($dataRead==$data);
     }      }
   
     /**      /**
     * Make a control key with the string containing datas      * Make a control key with the string containing datas
     *      *
Line 749  class Cache_Lite
Line 751  class Cache_Lite
             $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5);              $this->raiseError('Unknown controlType ! (available values are only \'md5\', \'crc32\', \'strlen\')', -5);
         }          }
     }      }
   
 }  }
   
 ?>  ?>

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

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