Source for file OCSP_FRMCONTR_CACHEDLIST_PEAR.phpclass

Documentation is available at OCSP_FRMCONTR_CACHEDLIST_PEAR.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.      * pear cache object for the list values
  65.      *
  66.      * @var Cache_Lite $myPearListCache 
  67.      */
  68.     private $myPearListCache=NULL;
  69.     
  70.     /**
  71.      * pear cache object for the description
  72.      * 
  73.      * @var Cache_Lite $myPearDescCache 
  74.      */
  75.     private $myPearDescCache=NULL;
  76.     
  77.     /**
  78.       *
  79.       * METHODS _____________________________________________
  80.       *
  81.       */    
  82.         
  83.  
  84.     //---------------------------------------------------
  85.     // cache methods
  86.     //---------------------------------------------------
  87.     
  88.     /**
  89.      * @return Cache_Lite 
  90.      */
  91.     protected function getPearListCacheObj()
  92.     {
  93.         if (!is_object($this->myPearListCache)) 
  94.         {
  95.               $arr_options array(
  96.                 'cacheDir'                  => __OCSP_PROJECTPATH__."cache"._OCSP_DIRSEP_."jOCSP"._OCSP_DIRSEP_."lists"._OCSP_DIRSEP_,
  97.                 'automaticSerialization'    => FALSE,
  98.                 'lifeTime'                  => $this->cacheRowTTL,
  99.                 'fileNameProtection'        => FALSE
  100.             );
  101.               $this->myPearListCache = new Cache_Lite($arr_options)
  102.         }
  103.         return $this->myPearListCache;
  104.     }
  105.     
  106.     /**
  107.      * @return Cache_Lite 
  108.      */
  109.     static function getPearDescCacheObj()
  110.     {
  111.           $arr_options array(
  112.                'cacheDir'                  => __OCSP_PROJECTPATH__."cache"._OCSP_DIRSEP_."jOCSP"._OCSP_DIRSEP_."lists"._OCSP_DIRSEP_,
  113.                'automaticSerialization'    => FALSE,
  114.                'lifeTime'                  => 6000,
  115.                'fileNameProtection'        => FALSE
  116.         );
  117.           return new Cache_Lite($arr_options)
  118.     }
  119.     
  120.     
  121.     /**
  122.      * caches the description
  123.      *
  124.      * @return boolean 
  125.      */
  126.     public function saveCacheDesc()
  127.     {
  128.         {
  129.             $arr_cachDesc=array(
  130.                 'FORMID'        => $this->myForm->getId(),
  131.                 'LISTQUERY'        => $this->getListQuery(),
  132.                 'FORMFILTER'    => $this->myFilter,
  133.                 'FORMORDERBY'    => $this->lst_orderBy,
  134.                 'FORMGROUPVALS' => $this->lst_groupValues,
  135.                 'CACHEFILLTIME' => $this->fillTime    
  136.             );
  137.             return $this->myPearDescCache->save(serialize($arr_cachDesc),"desc_".$this->getMyCacheKey());
  138.         }
  139.         return FALSE;
  140.     }    
  141.     
  142.     /**
  143.      * returns a desc array if cached
  144.      * 
  145.      * @param string $cacheKey 
  146.      * 
  147.      * @return array 
  148.      * 
  149.      */
  150.     public function getCacheDesc($cacheKey=NULL)
  151.     {
  152.         if (empty($cacheKey)) 
  153.         {
  154.             $cacheKey $this->getMyCacheKey();
  155.         }
  156.         
  157.         if (!is_object($this->myPearDescCache))
  158.         {
  159.         }
  160.         
  161.         
  162.         if (!empty($cacheKey&& is_object($this->myPearDescCache))
  163.         {
  164.             if ($str_cacheVal=$this->myPearDescCache->get("desc_".$cacheKey))
  165.             {
  166.                 $this->myCacheKey=$cacheKey;
  167.                 return unserialize($str_cacheVal);
  168.             }
  169.         }
  170.         return NULL;
  171.     }    
  172.         
  173.     /**
  174.      * returns if the cache is valid and not outtimed
  175.      *
  176.      * @return boolean 
  177.      * 
  178.      * @abstract
  179.      */
  180.     public function cacheIsValid(
  181.     {
  182.         if ($this->myCacheIsValidreturn TRUE;
  183.         return $this->getCachedValues();
  184.     }
  185.  
  186.     
  187.     /**
  188.      * loads the cached values into $this->myCachedRows
  189.      * or filles the cache if this has not happend
  190.      *
  191.      * @param boolean $debug 
  192.      * 
  193.      * @return boolean 
  194.      *
  195.      */
  196.     public function getCachedValues($debug=FALSE)
  197.     {
  198.         if ($this->getPearListCacheObj())
  199.         {
  200.             if ($str_data=$this->myPearListCache->get('rows_'.$this->getMyCacheKey()))
  201.             {
  202.                 
  203.                 $this->myCacheRows=unserialize(gzuncompress($str_data));
  204.                 $this->myCacheIsValid=TRUE;
  205.                 return TRUE;                
  206.             }
  207.         }
  208.         
  209.         return FALSE;        
  210.     }
  211.     
  212.     /**
  213.      * loads the values from the storage into $this->myCachedRows
  214.      * and cache $this->myCachedRows
  215.      *
  216.      * @param boolan $debug 
  217.      * 
  218.      * @return boolean 
  219.      * 
  220.      */
  221.     public function fillCache($debug=FALSE)
  222.     {
  223.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_CACHEDLIST_APC::fillCache");
  224.         
  225.         $this->getDBObj($debug);        // ensure $this->myDBObj is set
  226.         $this->getListQuery($debug);    // ensure $this->lstQuery is set        
  227.         
  228.            if (!empty($this->lstQuery))
  229.         {
  230.             $str_query=$this->lstQuery;
  231.             if (sizeof($this->myFilter))
  232.             {
  233.                 if (stristr($str_query,"where"))
  234.                 {
  235.                     $str_query.=" AND (";
  236.                 else {
  237.                     $str_query.=" WHERE (";
  238.                 }
  239.                 $str_whereAnd="";
  240.                 foreach($this->myFilter as $str_col => $m_val)
  241.                 {
  242.                     if (substr($str_col,0,1)=="?")
  243.                     {
  244.                         $str_query.=$str_whereAnd.$m_val;
  245.                     else {
  246.                         $str_query.=$str_whereAnd.$str_col."=".$this->myDBObj->qs_getSlashedValue($m_val);
  247.                     }
  248.                     $str_whereAnd=" AND ";
  249.                 }
  250.                 $str_query.=")";
  251.             }
  252.             if ($this->getOrderBy())
  253.             {
  254.                 $str_query.=" ORDER BY ".$this->getOrderBy();
  255.             }
  256.  
  257.             
  258.             if ($this->myCacheRows = $this->myDBObj->queryArray($str_query,-1,-1))
  259.             {
  260.                 if ($this->getPearListCacheObj())
  261.                 {
  262.                     if ($debug
  263.                         echo "alert('".$this->getMyCacheKey().": query ok".pcf_js_escape("\n".$str_query)."');";
  264.                     $str_cacheVals=gzcompress(serialize($this->myCacheRows));
  265.                     $this->myCacheIsValid=$this->myPearListCache->save($str_cacheVals,"rows_".$this->getMyCacheKey());
  266.                     $this->fillTime=time();                    
  267.                 }                                      
  268.                    return TRUE;
  269.             else {
  270.                 echo "alert('".$this->getMyCacheKey().": query failed".pcf_js_escape("\n".$str_query)."');";
  271.             }
  272.         }
  273.         
  274.         return FALSE;
  275.     }    
  276.     
  277.     
  278. }
  279. ?>

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