Source for file OCSP_CACHE_APC.phpclass

Documentation is available at OCSP_CACHE_APC.phpclass

  1. <?php
  2. /**
  3.   * openCSP class file OCSP_CACHE_APC.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_APC.phpclass,v 1.2 2008/06/20 15:29:55 pitlinz Exp $
  13.   */
  14.  
  15. // ---------------------------------------------------------
  16. // requirements
  17. // ---------------------------------------------------------
  18.  
  19. pcf_require_class('OCSP_CACHE',dirname(__FILE__"/OCSP_CACHE.phpclass");
  20.  
  21.  
  22. /**
  23.   * openCSP class OCSP_CACHE_APC
  24.   *
  25.   * @project Open CSP-Management
  26.   * @package default
  27.   *
  28.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  29.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  30.   *
  31.   * @since pk-11.06.2008
  32.   * @version $Id: OCSP_CACHE_APC.phpclass,v 1.2 2008/06/20 15:29:55 pitlinz Exp $
  33.   */
  34. class OCSP_CACHE_APC extends OCSP_CACHE
  35. {
  36.     /*** class constants  --------------------------------------------- */
  37.  
  38.     /**
  39.      * @constant string CLASS_SRC_FILE
  40.      *
  41.      */
  42.     const CLASS_SRC_FILE = __FILE__;
  43.     
  44.     /*** class variables  --------------------------------------------- */
  45.  
  46.     
  47.     /**
  48.      * @staticvar string $myNamespace 
  49.      */
  50.     protected static $myNamespace "";    
  51.         
  52.     
  53.     /*** class functions  --------------------------------------------- */
  54.     
  55.     /**
  56.      * returns if the cache type is usable on the system
  57.      *
  58.      * @param boolean $debug 
  59.      * 
  60.      * @return boolean 
  61.      */
  62.     public static function isUseable($debug=False)
  63.     {
  64.         return (function_exists('apc_fetch'));
  65.     }
  66.     
  67.     public static function getMyNamespace()
  68.     {
  69.         if (empty(self::$myNamespace))
  70.         {
  71.             self::$myNamespace md5(__OCSP_PROJECTPATH__);
  72.         }
  73.         return self::$myNamespace;
  74.     }    
  75.     
  76.     /*** compostion --------------------------------------------------- */
  77.     
  78.     /*** attributes  -------------------------------------------------- */
  79.  
  80.     /*** factory / construct  ----------------------------------------- */
  81.     
  82.     /**
  83.      * returns the instance of the singleton class
  84.      *
  85.      * @param string $group 
  86.      * 
  87.      * @return OCSP_CACHE 
  88.      */
  89.     public static function getInstance($group='DEFAULT')
  90.     {
  91.         // disable empty groups 
  92.         $group (empty($group'DEFAULT' $group);
  93.         
  94.         if (!isset(self::$cacheInstances['APC'][$group]|| !pcf_is_instance_of(self::$cacheInstances['APC'][$group],'OCSP_CACHE_APC'))
  95.         {
  96.              self::$cacheInstances['APC'][$groupnew OCSP_CACHE_APC($group);    
  97.         }         
  98.         return self::$cacheInstances['APC'][$group];
  99.     }
  100.     
  101.     /*** getter / setter ---------------------------------------------- */
  102.     
  103.     /**
  104.      * removes a value from the cache
  105.      * 
  106.      * @param string $aName 
  107.      */
  108.     public function unsetValue($aName)
  109.     {
  110.         unset($this->myValues[$aName]);
  111.         apc_delete($this->getMyNamespace()."_".$this->myGroup."_".$aName);
  112.     }
  113.     
  114.     /*** persistent storage ------------------------------------------- */
  115.     
  116.     /**
  117.      * returns a stored value
  118.      * 
  119.      * @param string $aName 
  120.      * 
  121.      * @return array 
  122.      */    
  123.     public function getStoredValueArr($aName)
  124.     {
  125.         if ($str_serVal apc_fetch($this->getMyNamespace()."_".$this->myGroup."_".$aName))
  126.         {
  127.             return unserialize($str_serVal);
  128.         }
  129.         
  130.         return Null;
  131.     }
  132.     
  133.     /**
  134.      * stores all temp cached values
  135.      * 
  136.      * @param boolean $debug 
  137.      */
  138.     public function storeMyValues($debug=False)
  139.     {
  140.         if (sizeof($this->myValues))
  141.         {
  142.             $str_namespace=$this->getMyNamespace();
  143.             foreach($this->myValues as $str_name => $arr_val)
  144.             {
  145.                 if (intval($arr_val['TTL']))
  146.                 {
  147.                     if (!$arr_val['TOU'])
  148.                     {
  149.                         // recalculate apc's ttl
  150.                         $ttl $arr_val['EXP'$arr_val['TTL'];
  151.                         if ($ttl 1// the 
  152.                         {
  153.                             unset($this->myValues[$str_name]);
  154.                             // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  155.                             continue;
  156.                             // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  157.                         }
  158.                     else {
  159.                         $arr_val['EXP'time(intval($arr_val['TTL']);
  160.                     }                    
  161.                 else {
  162.                     $int_ttl 0;
  163.                 }
  164.                 unset($arr_val['CHA'])// avoid memory usage
  165.                 apc_store($str_namespace."_".$this->myGroup."_".$str_name,serialize($arr_val),$int_ttl);
  166.                 unset($this->myValues[$str_name]);
  167.             }
  168.         }
  169.     }
  170. }
  171.  
  172. ?>

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