Source for file OCSP_CACHE_FILE.phpclass

Documentation is available at OCSP_CACHE_FILE.phpclass

  1. <?php
  2. /**
  3.   * openCSP class file OCSP_CACHE_FILE.phpclass
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package default
  7.   *
  8.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-11.06.2008
  12.   * @version $Id: OCSP_CACHE_FILE.phpclass,v 1.6 2008/12/12 17:35:14 pitlinz Exp $
  13.   */
  14.  
  15. // ---------------------------------------------------------
  16. // requirements
  17. // ---------------------------------------------------------
  18.  
  19. pcf_require_class('OCSP_CACHE',dirname(__FILE__"/OCSP_CACHE.phpclass");
  20.  
  21. if (!function_exists('pcf_checkDir')) {
  22.     require __OCSP_PHPINCPATH__ "common" _OCSP_DIRSEP_ "pcf_directory.phpinc";
  23. }
  24.  
  25. if (!function_exists('pcf_checkFileName')) {
  26.     require __OCSP_PHPINCPATH__ "common" _OCSP_DIRSEP_ "pcf_file.phpinc";    
  27. }
  28.  
  29. /**
  30.   * openCSP class OCSP_CACHE_FILE
  31.   *
  32.   * @project Open CSP-Management
  33.   * @package default
  34.   *
  35.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  36.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  37.   *
  38.   * @since pk-11.06.2008
  39.   * @version $Id: OCSP_CACHE_FILE.phpclass,v 1.6 2008/12/12 17:35:14 pitlinz Exp $
  40.   */
  41. class OCSP_CACHE_FILE extends OCSP_CACHE
  42. {
  43.     /*** class constants  --------------------------------------------- */
  44.  
  45.     /**
  46.      * @constant string CLASS_SRC_FILE
  47.      *
  48.      */
  49.     const CLASS_SRC_FILE = __FILE__;
  50.     
  51.     /*** class variables  --------------------------------------------- */
  52.  
  53.     /**
  54.      * cache subdir
  55.      * @var string $cacheSubDirName 
  56.      */        
  57.     protected static $cacheSubDirName 'ocsp_cache';
  58.     
  59.     /*** class functions  --------------------------------------------- */
  60.     
  61.     /**
  62.      * returns if the cache type is usable on the system
  63.      *
  64.      * @param boolean $debug 
  65.      * 
  66.      * @return boolean 
  67.      * 
  68.      * @version pk-08-06-20
  69.      */
  70.     public static function isUseable($debug=False)
  71.     {
  72.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_CACHE_FILE::isUseable()");
  73.         
  74.         $str_dir OCSP_OBJ::getConf('CACHEPATH'self::$cacheSubDirName;
  75.         
  76.         if (intval(pcf_checkDir($str_dir,True,0770)))
  77.         {
  78.             if ($debugechoDebugLine(__FILE__,__LINE__,"cache path: " $str_dir " is writeable");
  79.             return (is_writable($str_dir));
  80.         else {
  81.             if ($debugechoDebugLine(__FILE__,__LINE__,"cache path: " $str_dir " is NOT writeable");
  82.             return False;
  83.         }
  84.     }
  85.     
  86.     
  87.     /*** compostion --------------------------------------------------- */
  88.     
  89.     /*** attributes  -------------------------------------------------- */
  90.  
  91.     /**
  92.      * @var bool $fileLoaded 
  93.      */
  94.     private $fileLoaded = False;
  95.     
  96.     /*** factory / construct  ----------------------------------------- */
  97.     
  98.     /**
  99.      * returns the instance of the singleton class
  100.      *
  101.      * @param string $group 
  102.      * 
  103.      * @return OCSP_CACHE 
  104.      */
  105.     public static function getInstance($group='DEFAULT')
  106.     {
  107.         // disable empty groups 
  108.         $group (empty($group'DEFAULT' $group);
  109.         
  110.         if (!isset(self::$cacheInstances['FILE'][$group]|| !pcf_is_instance_of(self::$cacheInstances['FILE'][$group],'OCSP_CACHE_FILE'))
  111.         {
  112.              self::$cacheInstances['FILE'][$groupnew OCSP_CACHE_FILE($group);    
  113.         }         
  114.         return self::$cacheInstances['FILE'][$group];
  115.     }
  116.     
  117.     /*** getter / setter ---------------------------------------------- */
  118.     
  119.     /**
  120.      * retuns the cache file path on the server
  121.      *
  122.      * @param boolean $debug 
  123.      * 
  124.      * @return string 
  125.      */
  126.     protected function getCacheFilePath($debug=False)
  127.     {
  128.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CACHE_FILE::getCacheFilePath()","Group: " $this->myGroup);
  129.         $str_dir OCSP_OBJ::getConf('CACHEPATH'self::$cacheSubDirName _OCSP_DIRSEP_;
  130.         $str_fileName =    pcf_checkFileName($this->myGroup".cache";
  131.         
  132.         if ($debugechoDebugLine(__FILE__,__LINE__,"returning: "pcf_checkFilePath($str_dir.$str_fileName));
  133.         return pcf_checkFilePath($str_dir.$str_fileName);
  134.     }
  135.     
  136.     /**
  137.      * removes a value from the cache
  138.      * 
  139.      * @param string $aName 
  140.      * @param boolean $debug 
  141.      */
  142.     public function unsetValue($aName)
  143.     {
  144.         if (!$this->fileLoaded)
  145.         {
  146.             $this->loadMyValues();
  147.         }
  148.         unset($this->myValues[$aName]);
  149.     }
  150.     
  151.     /*** persistent storage ------------------------------------------- */
  152.     
  153.     /**
  154.      * loads the cache values from the file
  155.      * 
  156.      * @param boolean $debug 
  157.      */
  158.     protected function loadMyValues($debug=False)
  159.     {
  160.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CACHE_FILE::loadMyValues();");
  161.         $str_filePath $this->getCacheFilePath();
  162.         if (pcf_is_file($str_filePath))
  163.         {
  164.             if ($debugechoDebugLine(__FILE__,__LINE__,"loading file " $str_filePath "<br />\$this->myValues: <pre>" print_r($this->myValues,True"</pre>");
  165.             $str_allValues file_get_contents($str_filePath);
  166.             $this->myValues = array_merge(unserialize($str_allValues),$this->myValues);
  167.         }
  168.         
  169.         if ($debugechoDebugLine(__FILE__,__LINE__,"\$this->myValues: <pre>" print_r($this->myValues,True"</pre>");
  170.         $this->fileLoaded=True;        
  171.     }
  172.     
  173.     
  174.     /**
  175.      * returns a stored value
  176.      * 
  177.      * @param string $aName 
  178.      * @param boolean $debug 
  179.      * 
  180.      * @return array 
  181.      */    
  182.     public function getStoredValueArr($aName,$debug=False)
  183.     {    
  184.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CACHE_FILE::getStoredValueArr($aName)");
  185.         if (!$this->fileLoaded)
  186.         {
  187.             $this->loadMyValues($debug);
  188.         }
  189.         
  190.         if (isset($this->myValues[$aName]))
  191.         {
  192.             return $this->myValues[$aName];
  193.         else {
  194.             return Null;
  195.         }
  196.     }
  197.     
  198.     /**
  199.      * stores all temp cached values
  200.      * 
  201.      * @param boolean $debug 
  202.      */
  203.     public function storeMyValues($debug=False)
  204.     {    
  205.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CACHE_FILE::storeMyValues();");        
  206.         if (sizeof($this->myValues))
  207.         {
  208.             $arr_newValues array();
  209.             
  210.             $bol_changed False;
  211.             foreach($this->myValues as $str_name => $arr_val)
  212.             {
  213.                 if (intval($arr_val['TTL']))
  214.                 {
  215.                     if (!$arr_val['TOU'])
  216.                     {
  217.                         // recalculate apc's ttl
  218.                         $ttl $arr_val['EXP'$arr_val['TTL'];
  219.                         if ($ttl 1// the 
  220.                         {
  221.                             unset($this->myValues[$str_name]);
  222.                             $bol_changed True;
  223.                         }
  224.                     else {
  225.                         $arr_val['EXP'time(intval($arr_val['TTL']);
  226.                         $bol_changed True;
  227.                     }                    
  228.                 }
  229.                 $bol_changed ((isset($arr_val['CHA']&& $arr_val['CHA']True False);            
  230.                 unset($this->myValues[$str_name]['CHA']);
  231.                 if (!$this->fileLoaded)
  232.                 {
  233.                     $arr_newValues[$str_name$this->myValues[$str_name];
  234.                 }
  235.             }
  236.             
  237.             if ($bol_changed)
  238.             {                
  239.                 if (!$this->fileLoaded)
  240.                 {
  241.                     $this->loadMyValues();
  242.                     $this->myValues = array_merge($this->myValues,$arr_newValues);                    
  243.                 }
  244.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Setting to file " $this->getCacheFilePath("<pre>" print_r($this->myValues,True"</pre>");                
  245.                 file_put_contents($this->getCacheFilePath(),serialize($this->myValues));
  246.             }
  247.             
  248.             $this->myValues=array();
  249.             $this->fileLoaded=False;
  250.         else if($this->fileLoaded{
  251.             @unlink($this->getCacheFilePath());
  252.         }
  253.     }
  254. }
  255.  
  256. ?>

Documentation generated on Thu, 08 Jan 2009 17:45:12 +0100 by phpDocumentor 1.4.0a2