Source for file OCSP_FRMCONTR_CACHEDLIST_APC.phpclass

Documentation is available at OCSP_FRMCONTR_CACHEDLIST_APC.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_FRMCONTR_CACHEDLIST_APC.phpclass
  4.   *
  5.   *
  6.   * @project    Open CSP-Management
  7.   * @package    forms
  8.   * @category   dbms_form
  9.   *
  10.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @since  pk-07-07-02
  14.   *
  15.   ***/
  16.  
  17. require_once dirname(__FILE__)._OCSP_DIRSEP_."OCSP_FRMCONTR_CACHEDLIST.phpclass";
  18.  
  19. /**
  20.   * abstract class OCSP_FRMCONTR_CACHEDLIST
  21.   *
  22.   * @project    Open CSP-Management
  23.   * @package    forms
  24.   * @category   dbms_form
  25.   *
  26.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  27.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  28.   *
  29.   * @since  pk-07-07-02
  30.   *
  31.   */
  32. {
  33.     /*** class constants  --------------------------------------------- */
  34.  
  35.     /**
  36.       * @constant string CLASS_SRC_FILE
  37.       * 
  38.       * @abstract
  39.       */
  40.     const CLASS_SRC_FILE = __FILE__;
  41.     
  42.     /**
  43.      * type of the cache used
  44.      * 
  45.      * @constant int _MY_FRMLIST_CACHETYPE_
  46.      * @abstract
  47.      * 
  48.      */
  49.         
  50.     /*** class variables  --------------------------------------------- */
  51.     
  52.     /*** compositions ------------------------------------------------  */
  53.  
  54.     /*** aggregation -------------------------------------------------- */
  55.  
  56.     /*** attributes --------------------------------------------------- */
  57.  
  58.       /**
  59.        * @var boolean $myCacheIsValid 
  60.        */
  61.     private $myCacheIsValid=FALSE;
  62.  
  63.     /**
  64.       *
  65.       * METHODS _____________________________________________
  66.       *
  67.       */    
  68.  
  69.     /**
  70.      * returns if the cache is valid and not outtimed
  71.      *
  72.      * @return boolean 
  73.      * 
  74.      * @abstract
  75.      */
  76.     public function cacheIsValid(
  77.     {
  78.         if ($this->myCacheIsValidreturn TRUE;
  79.         return $this->getCachedValues();
  80.     }
  81.  
  82.     
  83.     /**
  84.      * loads the cached values into $this->myCachedRows
  85.      * or filles the cache if this has not happend
  86.      *
  87.      * @param boolean $debug 
  88.      * 
  89.      * @return boolean 
  90.      *
  91.      */
  92.     public function getCachedValues($debug=FALSE)
  93.     {
  94.         if ($this->myCacheRows=apc_fetch('rows_'.$this->getMyCacheKey()))
  95.         {
  96.             // echo "document.getElementById('lstDebug').innerHTML='<pre>".pcf_js_escape(print_r($this->myCacheRows,TRUE))."</pre>';";
  97.             $this->myCacheIsValid=TRUE;
  98.             return TRUE;
  99.         else {
  100.             return FALSE;
  101.         }
  102.         
  103.     }
  104.     
  105.     /**
  106.      * loads the values from the storage into $this->myCachedRows
  107.      * and cache $this->myCachedRows
  108.      *
  109.      * @param boolan $debug 
  110.      * 
  111.      * @return boolean 
  112.      * 
  113.      */
  114.     public function fillCache($debug=FALSE)
  115.     {
  116.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_CACHEDLIST_APC::fillCache");
  117.         
  118.         $this->getDBObj($debug);        // ensure $this->myDBObj is set
  119.         $this->getListQuery($debug);    // ensure $this->lstQuery is set        
  120.         
  121.            if (!empty($this->lstQuery))
  122.         {
  123.             $str_query=$this->lstQuery;
  124.             if (sizeof($this->myFilter))
  125.             {
  126.                 if (stristr($str_query,"where"))
  127.                 {
  128.                     $str_query.=" AND (";
  129.                 else {
  130.                     $str_query.=" WHERE (";
  131.                 }
  132.                 $str_whereAnd="";
  133.                 foreach($this->myFilter as $str_col => $m_val)
  134.                 {
  135.                     if (substr($str_col,0,1)=="?")
  136.                     {
  137.                         $str_query.=$str_whereAnd.$m_val;
  138.                     else {
  139.                         $str_query.=$str_whereAnd.$str_col."=".$this->myDBObj->qs_getSlashedValue($m_val);
  140.                     }
  141.                     $str_whereAnd=" AND ";
  142.                 }
  143.                 $str_query.=")";
  144.             }
  145.             if ($this->getOrderBy())
  146.             {
  147.                 $str_query.=" ORDER BY ".$this->getOrderBy();
  148.             }
  149.  
  150.             
  151.             if ($this->myCacheRows = $this->myDBObj->queryArray($str_query,-1,-1))
  152.             {
  153.                 //echo "document.getElementById('lstDebug').innerHTML='<pre>".pcf_js_escape(print_r($this->myCacheRows,TRUE))."</pre>';";
  154.                 echo "alert('".pcf_js_escape("apc_store('rows_".$this->getMyCacheKey().",\$this->myCacheRows,\$this->cacheRowTTL)")."');";
  155.                 $this->myCacheKey=apc_store('rows_'.$this->getMyCacheKey(),$this->myCacheRows,$this->cacheRowTTL);
  156.                    $this->fillTime=time();
  157.                    
  158.                    
  159.                    return TRUE;
  160.             else {
  161.                 echo "alert('".$this->getMyCacheKey().": query failed".pcf_js_escape("\n".$str_query)."');";
  162.             }
  163.         }
  164.         
  165.         return FALSE;
  166.     }    
  167.     
  168.     
  169. }
  170. ?>

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