Source for file OCSP_CMS_PEARCACHE.phpclass
Documentation is available at OCSP_CMS_PEARCACHE.phpclass
* Class file OCSP_CMS_PEARCACHE.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @requires Cache/Lite.php [PEAR]
* @see http://pear.php.net/manual/en/package.caching.cache-lite.php
* ---------------------------------------------------
* common settings and requirements
define('_OCSP_PEARPATH_',''); // pear is in the include path
require_once _OCSP_PEARPATH_.
"Cache/Lite.php";
* Class OCSP_CMS_PEARCACHE.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @requires Cache/Lite.php [PEAR]
* @uses $GLOBALS['OCSP']['OBJCACHEPATH']
* @see http://pear.php.net/manual/en/package.caching.cache-lite.php
/** -----------------------------------------------------
/** -----------------------------------------------------
* @var array $projCachArr
* @var Cache_Lite $myMenuCache
* @var Cache_Lite $myPageCache
/** -----------------------------------------------------
protected $ttl =
604800; // one week
* index of the menu tree in $GLOBALS['OCSP_VAL']['DBMS_TREE']
* @var string $menuTreeIndex
* @var array $menNodeValsLoaded ([$menuTreeIndex]=TRUE/FALSE)
* METHODS _____________________________________________
/** -----------------------------------------------------
if (!isset
($GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE']))
$GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE']=
&$this;
/** -----------------------------------------------------
* getter & setter methods
* @requires $GLOBALS['OCSP']['PHPINCPATH']."common/pcf_directory.phpinc";
//if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::getProjCacheObj($projId)");
'cacheDir' =>
$this->getRootPath().
"PROJ_".
$projId.
"/",
'automaticSerialization' =>
TRUE,
'lifeTime' =>
$this->ttl,
'fileNameProtection' =>
FALSE
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/pcf_directory.phpinc";
if (!pcf_checkDir($arr_option['cacheDir'],TRUE,0700,$debug))
$this->projCachArr[$projId]=
new Cache_Lite($arr_option);
* gets a projects database values from the cache
return $obj_cache->get('PROJDBVAL');
* stores a projects database values to the cache
* @param CMS_PROJECT $aProj
$arr_projVals=
$aProj->getDBVal();
$arr_projVals['PEARCACHE_TS']=
time();
if (!$obj_cache->save($arr_projVals,'PROJDBVAL'))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<p>Error Saving Cache</p><pre>".
print_r($obj_cache,TRUE).
"</pre>");
* clears the cache by removing the cache directory
* @param CMS_PROJECT $aProject
* @param boolean $chkDir (if true the existens of page cache dir is checked)
'automaticSerialization' =>
TRUE,
'lifeTime' =>
$this->ttl,
'fileNameProtection' =>
FALSE
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/pcf_directory.phpinc";
if (!pcf_checkDir($arr_option['cacheDir'],TRUE,0700,$debug))
ocsp_logError(__FILE__
,__LINE__
,"check dir ".
$arr_option['cacheDir'].
" failed");
* returns an array with all data for a menu node
* 'MENVAL' => CMS_MENU_NODE->getDBVal(),
* 'PROJVAL'=> CMS_PROJECT->getDBVal()
* @return mixed array or false if cache failed
* returns an array with page values
* @return mixed array of false if cache failed
if (isset
($arr_cache['MENVAL']) &&
is_array($arr_cache['MENVAL']))
return $arr_cache['MENVAL'];
* @param CMS_PAGE_V2 $aPage
$this->getMenuCacheObj(TRUE,$debug); // ensure $this->myMenuCache is set and the directory exists
$arr_cache['MENVAL']=
$aNode->getDBVal();
$arr_cache['MENVAL']['PEARCACHE_TS']=
$aNode->getPopulateTs();
$arr_cache['MENVAL']['CMS_MENU_TREE_KEY']=
$aNode->getGlobalTreeKey();
if ($obj_proj=
$aNode->getMyProject($debug))
$arr_cache['PROJVAL']=
$obj_proj->getDBVal();
$arr_cache['PROJVAL']['PEARCACHE_TS']=
$obj_proj->getPopulateTs();
if (!$this->myMenuCache->save($arr_cache,'MENU_'.
$aNode->getId()))
* @param mixed $aId (int) menu id or (string) PROJ_$*PROJ_ID$ for project root pages
* @param mixed $aId (int) menu id or (string) PROJ_$*PROJ_ID$ for project root pages
ocsp_logError(__FILE__
,__LINE__
,"error cacheing page data",E_WARNING);
$arr_cache['PEARCACHE_TS']=
time();
if (!$this->myMenuCache->save($arr_cache,'PAGLSTVAL_'.
$aId))
ocsp_logError(__FILE__
,__LINE__
,"error cacheing page data",E_WARNING);
* @param boolean $chkDir (if true the existens of page cache dir is checked)
'automaticSerialization' =>
TRUE,
'lifeTime' =>
$this->ttl,
'fileNameProtection' =>
FALSE
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/pcf_directory.phpinc";
if (!pcf_checkDir($arr_option['cacheDir'],TRUE,0700,$debug))
ocsp_logError(__FILE__
,__LINE__
,"check dir ".
$arr_option['cacheDir'].
" failed");
* returns an array with all data for a page
* 'PAGVAL' => CMS_PAGE_V2->getDBVal(),
* 'MENVAL' => CMS_MENU_NODE->getDBVal(),
* 'PROJVAL'=> CMS_PROJECT->getDBVal()
* @return mixed array or false if cache failed
* returns an array with page values
* @return mixed array of false if cache failed
if (isset
($arr_cache['PAGVAL']) &&
is_array($arr_cache['PAGVAL']))
return $arr_cache['PAGVAL'];
* @param CMS_PAGE_V2 $aPage
if (!intval($aPage->getId())) return FALSE;
$this->getPageCacheObj(TRUE,$debug); // ensure $this->myPageCache is set and the directory exists
$arr_cache['PAGVAL']=
$aPage->getDBVal();
$arr_cache['PAGVAL']['PEARCACHE_TS']=
$aPage->getPopulateTs();
if ($obj_menu=
$aPage->getMyMenuNode($debug))
$arr_cache['MENVAL']=
$obj_menu->getDBVal();
$arr_cache['MENVAL']['PEARCACHE_TS']=
$obj_menu->getPopulateTs();
if ($obj_proj=
$aPage->getMyProject($debug))
$arr_cache['PROJVAL']=
$obj_proj->getDBVal();
$arr_cache['PROJVAL']['PEARCACHE_TS']=
$obj_proj->getPopulateTs();
if (!$this->myPageCache->save($arr_cache,'PAGE_'.
$aPage->getId()))
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/** -----------------------------------------------------
/** -----------------------------------------------------
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_CMS_PEARCACHE::getProjIdFromHTTP_HOST()",$_SERVER['HTTP_HOST']);
'automaticSerialization' =>
TRUE,
'lifeTime' =>
$this->ttl,
'fileNameProtection' =>
FALSE
$obj_cache=
new Cache_Lite($arr_option);
if ($arr_prjData=
$obj_cache->get('PROJLST'))
if (isset
($arr_prjData[strtoupper($_SERVER['HTTP_HOST'])]['PROJ_ID']))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"CacheHit: ".
intval($arr_prjData[$_SERVER['HTTP_HOST']]['PROJ_ID']));
return intval($arr_prjData[$_SERVER['HTTP_HOST']]['PROJ_ID']);
foreach($arr_prjData as $host =>
$arr_vals)
if (!empty($arr_vals['PROJ_URLREGEX']) &&
($a_regExpNames=
explode("\n",str_replace("\r","",$arr_vals['PROJ_URLREGEX']))))
if ($arr_vals['PROJ_URL']==
strtoupper($_SERVER['SERVER_NAME']))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"CacheHit SERVER_NAME: ".
intval($arr_vals['PROJ_ID']));
return intval($arr_vals['PROJ_ID']);
// we have regular expressions to check
foreach($a_regExpNames as $s_pattern)
$s_pattern=
trim($s_pattern);
if ((!empty($s_pattern)) &&
(@preg_match($s_pattern,$_SERVER['SERVER_NAME'])))
return intval($arr_vals['PROJ_ID']);
} // foreach($arr_prjData as $host => $arr_vals)
} // (is_array($arr_prjData))
* adds or replaces a host if $aId is 0 the host is removed from the cache
* @param int $aId (0 -> unset the cache object)
* @param string $urlRegex
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_CMS_PEARCACHE::addProjIdFromHTTP_HOST()",$_SERVER['HTTP_HOST']);
'automaticSerialization' =>
TRUE,
'lifeTime' =>
$this->ttl,
'fileNameProtection' =>
FALSE
$obj_cache=
new Cache_Lite($arr_option);
$arr_prjData=
$obj_cache->get('PROJLST');
if (empty($aHost)) $aHost=
$_SERVER['HTTP_HOST'];
if (isset
($arr_prjData[$aHost]))
unset
($arr_prjData[$aHost]);
$arr_prjData[$aHost]=
array(
'PROJ_URLREGEX' =>
$urlRegex,
'PROJ_URL' =>
strtoupper(!empty($aServerName) ?
$aServerName :
$_SERVER['SERVER_NAME'])
$arr_prjData['PEARCACHE_TS']=
time();
$obj_cache->save($arr_prjData,'PROJLST');
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"OCSP_CMS_PEARCACHE::clearProjIdFromHTTP_HOST()",$_SERVER['HTTP_HOST']);
'automaticSerialization' =>
TRUE,
'lifeTime' =>
$this->ttl,
'fileNameProtection' =>
FALSE
$obj_cache=
new Cache_Lite($arr_option);
return $obj_cache->get('CSS_PROJ');
$cssArr['PEARCACHE_TS']=
time();
if (!$obj_cache->save($cssArr,'CSS_PROJ'))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<p>Error Saving Cache</p><pre>".
print_r($obj_cache,TRUE).
"</pre>");
* page template cache methods
return $obj_cache->get('PTMPLROW_'.
$tmplId);
$tmplRow['PEARCACHE_TS']=
time();
$obj_cache->save($tmplRow,'PTMPLROW_'.
$tmplId);
* sets the menuTreeKey (index of $GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex])
* @param string $treeName
return $obj_cache->get('MENUKEYTREE');
* stores a projects database values to the cache
* @param CMS_PROJECT $aProj
$keyArr['PEARCACHE_TS']=
time();
if (!$obj_cache->save($keyArr,'MENUKEYTREE'))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<p>Error Saving Cache</p><pre>".
print_r($obj_cache,TRUE).
"</pre>");
* returns if the global menu nodeval array has been loaded
* @param string $menuTreeIndex
* sets the global environment of the tree from the cache
if (!$arr_cache=
$obj_cache->get('MENUNODESVAL'.
$this->menuTreeIndex))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"MENUNODESVAL is empty");
$GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODEVAL']=
$arr_cache;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"cache values: <pre style=\"font-size: 60%\">".
print_r($GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODEVAL'],TRUE).
"</pre>");
* stores a projects database values to the cache
* @param CMS_PROJECT $aProj
function setMenuNodesVal($projId,$debug=FALSE)
if ($debug) echoDebugMethod(__FILE__,get_class($this),"OCSP_CMS_PEARCACHE::setMenuNodesVal($projId)",$this->menuTreeIndex);
if (empty($this->menuTreeIndex)) $this->menuTreeIndex='T_CMS_MENU'.$projId;
if ($obj_cache=$this->getProjCacheObj($projId,TRUE,$debug))
$arr_Nodes = &$GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODEVAL'];
if (isset($GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODES']))
foreach($GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->menuTreeIndex]['NODES'] as $idx => &$o_node)
if (pcf_is_instance_of($o_node,'DBMS_TREE_NODE'))
if ($debug) echoDebugLine(__FILE__,__LINE__,"adding Node ".$o_node->getId());
$arr_Nodes[$o_node->getId()]['DATA'] =$o_node->getDBVal();
$arr_Nodes[$o_node->getId()]['PEARCACHE_TS']=$o_node->getPopulateTs();
if ($debug) echoDebugLine(__FILE__,__LINE__,"not instance of DBMS_TREE_NODE <pre>".print_r($o_node,TRUE)."</pre>");
if (!$obj_cache->save($arr_Nodes,'MENUNODESVAL'.$this->menuTreeIndex))
if ($debug) echoDebugLine(__FILE__,__LINE__,"<p>Error Saving Cache</p><pre>".print_r($obj_cache,TRUE)."</pre>");
$this->menNodeValsLoaded[$projId][$this->menuTreeIndex]=TRUE;
/** -----------------------------------------------------
/** -----------------------------------------------------
* @param CMS_PAGE_V2 $pageObj
return $obj_cache->get('PAGHEADER_'.
$pageObj->getId());
} // end class OCSP_CMS_PEARCACHE
Documentation generated on Thu, 08 Jan 2009 17:45:19 +0100 by phpDocumentor 1.4.0a2