Source for file OCSP_CACHE.phpclass

Documentation is available at OCSP_CACHE.phpclass

  1. <?php
  2. /**
  3.   * openCSP abstract class file OCSP_CACHE.phpclass
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package cache
  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.phpclass,v 1.3 2008/07/03 06:25:46 pitlinz Exp $
  13.   */
  14.  
  15. // ---------------------------------------------------------
  16. // requirements
  17. // ---------------------------------------------------------
  18.  
  19. if (!interface_exists('INFA_OCSP_CACHE'))
  20. {
  21.     require dirname(__FILE___OCSP_DIRSEP_ "INFA_OCSP_CACHE.phpclass";
  22. }
  23.  
  24. /**
  25.   * openCSP abstract class OCSP_CACHE
  26.   * 
  27.   * uses the singleton design pattern
  28.   *
  29.   * @project Open CSP-Management
  30.   * @package cache
  31.   *
  32.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  33.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  34.   *
  35.   * @since pk-11.06.2008
  36.   * @version $Id: OCSP_CACHE.phpclass,v 1.3 2008/07/03 06:25:46 pitlinz Exp $
  37.   */
  38. abstract class OCSP_CACHE implements INFA_OCSP_CACHE
  39. {
  40.     /*** class constants  --------------------------------------------- */
  41.     
  42.     /*** static vars  ------------------------------------------------- */
  43.     
  44.     /**
  45.      * array holding the instances of the implementation
  46.      * @staticvar array $cacheInstances 
  47.      */
  48.     protected static $cacheInstances array();
  49.         
  50.     /*** compostion --------------------------------------------------- */
  51.     
  52.     /*** attributes  -------------------------------------------------- */
  53.         
  54.     /**
  55.      * @var string $myGroup 
  56.      */
  57.     protected $myGroup = 'DEFAULT';
  58.     
  59.     /**
  60.      * array of values currently loaded in the memory
  61.      *
  62.      * array keys:
  63.      * - 'VAL' => (mixed) the value to cache
  64.      * - 'TTL' => (int) time to life of the cached value
  65.      * - 'EXP' => (timestamp) the value expires
  66.      * - 'TOU' => (boolean) touch the value on a read
  67.      * - 'CHA' => (boolean) the value has changed
  68.      * 
  69.      * @var array $myValues 
  70.      * 
  71.      * 
  72.      */
  73.     protected $myValues = array();
  74.     
  75.     /*** factory / construct / destruct / auto ------------------------ */
  76.     
  77.     /**
  78.      * constructor
  79.      *
  80.      * @param string $group 
  81.      */
  82.     public function __construct($group)
  83.     {
  84.         $this->myGroup=(empty($group'DEFAULT' $group);
  85.     }
  86.     
  87.     /**
  88.      * store all values on destruct
  89.      */
  90.     public function __destruct()
  91.     {
  92.         $this->storeMyValues();
  93.     }
  94.     
  95.     /*** getter / setter ---------------------------------------------- */
  96.  
  97.     /**
  98.      * returns a cached value
  99.      *
  100.      * @param string $aName 
  101.      * @param boolean $debug 
  102.      * 
  103.      * @return mixed 
  104.      */
  105.     public function getValue($aName,$debug=False)
  106.     {
  107.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CACHE::getValue(".$aName.")");
  108.         if (isset($this->myValues[$aName]['VAL'])) 
  109.         {
  110.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning already set value");
  111.             if (intval($this->myValues[$aName]['TTL']))
  112.             {
  113.                 if (time($this->myValues[$aName]['EXP'])
  114.                 {
  115.                     return Null;
  116.                 else {
  117.                     return $this->myValues[$aName]['VAL'];
  118.                 }
  119.             else {
  120.                 return $this->myValues[$aName]['VAL'];
  121.             }            
  122.         }
  123.         
  124.         if ($arr_val $this->getStoredValueArr($aName,$debug))
  125.         {
  126.             $arr_val['CHA'False;
  127.             if (intval($arr_val['TTL']))
  128.             {
  129.                 if (time($arr_val['EXP'])
  130.                 {
  131.                     unset($this->myValues[$aName]);
  132.                     return Null;
  133.                 else {
  134.                     $this->myValues[$aName$arr_val;
  135.                     return $arr_val['VAL'];
  136.                 }
  137.             else {
  138.                 $this->myValues[$aName$arr_val;
  139.                 return $arr_val['VAL'];
  140.             }
  141.         else {
  142.             return Null;
  143.         }
  144.     }
  145.  
  146.     /**
  147.      * sets a value
  148.      * 
  149.      * NOTE the value is stored on destruct
  150.      *
  151.      * @param string $aName 
  152.      * @param mixed $aValue 
  153.      * @param mixed $ttl 
  154.      * @param boolean $autotouch (if true ttl will be expanded on every use of the value)
  155.      * 
  156.      */
  157.     public function setValue($aName,$aValue,$ttl=0,$autotouch=False)
  158.     {
  159.         $this->myValues[$aName]=array(
  160.                 'VAL' => $aValue,
  161.                 'TTL' => $ttl,
  162.                 'EXP' => time($ttl,
  163.                 'TOU' => $autotouch,    
  164.                 'CHA' => True    
  165.             );
  166.     }
  167.         
  168. }
  169. ?>

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