Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Fix CronksDataModel caching feature
Browse files Browse the repository at this point in the history
We now add a timestamp to the cached data, to be able to determine if the cache
is still valid.

The timestamp is compared against the filemtime of the XML cache on disk
(cronks.xml cache).

In addition the handling of the param ($all) has been disabled in the
getXmlCronks function, it is handled in the function combinedData
(since 5da9fae). This will avoid having only a partial cache.

fixes #3919
  • Loading branch information
lazyfrosch committed Apr 17, 2013
1 parent 7b73c55 commit 2fadaca
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/modules/Cronks/models/Provider/CronksDataModel.class.php
Expand Up @@ -227,10 +227,19 @@ private function checkPrincipals($listofprincipals) {
* @return array
*/
private function getXmlCronks($all=false) {
// pull cronk xml data from the cache
$cached = $this->user->getStorage()->read("icinga.cronks.cache.xml");

if($cached) {
return $cached;
// get me a timestamp for our xml disk cache for cronks
$configcache_ts = filemtime(AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir'). '/cronks.xml'));

// do we have any cache?
if(isset($cached) and isset($cached["data"])) {
// is the cached data newer than that in the xml cache on disk?
if(isset($cached["timestamp"]) and $cached["timestamp"] > $configcache_ts) {
// return cache
return $cached["data"];
}
}

$out = array();
Expand All @@ -257,9 +266,11 @@ private function getXmlCronks($all=false) {
elseif(isset($cronk['disabled']) && $cronk['disabled'] == true) {
continue;
}
/* ignoring all here - because the cache needs all cronks! -mfrosch
elseif($all == false && isset($cronk['hide']) && $cronk['hide'] == true) {
continue;
}
*/
elseif(!isset($cronk['action']) || !isset($cronk['module'])) {
$this->getContext()->getLoggerManager()->log('No action or module for cronk: '. $uid, AgaviLogger::ERROR);
continue;
Expand All @@ -286,7 +297,8 @@ private function getXmlCronks($all=false) {
);

}
$this->user->getStorage()->write("icinga.cronks.cache.xml",$out);
// write data to the cache, with a timestamp
$this->user->getStorage()->write("icinga.cronks.cache.xml",array("timestamp" => time(), "data" => $out));
return $out;
}

Expand Down

0 comments on commit 2fadaca

Please sign in to comment.