[icinga-checkins] icinga.org: icinga-web/next: Fix CronksDataModel caching feature

git at icinga.org git at icinga.org
Wed Apr 17 17:41:20 CEST 2013


Module: icinga-web
Branch: next
Commit: 2fadacace9f010572072fb5f35d448d5d68a3d4a
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=2fadacace9f010572072fb5f35d448d5d68a3d4a

Author: Markus Frosch <markus at lazyfrosch.de>
Date:   Wed Apr 17 17:34:58 2013 +0200

Fix CronksDataModel caching feature

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 5da9fae0). This will avoid having only a partial cache.

fixes #3919

---

 .../models/Provider/CronksDataModel.class.php      |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/app/modules/Cronks/models/Provider/CronksDataModel.class.php b/app/modules/Cronks/models/Provider/CronksDataModel.class.php
index d3a38cf..bba8a9d 100644
--- a/app/modules/Cronks/models/Provider/CronksDataModel.class.php
+++ b/app/modules/Cronks/models/Provider/CronksDataModel.class.php
@@ -227,10 +227,19 @@ class Cronks_Provider_CronksDataModel extends CronksBaseModel implements AgaviIS
      * @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();
@@ -257,9 +266,11 @@ class Cronks_Provider_CronksDataModel extends CronksBaseModel implements AgaviIS
             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;
@@ -286,7 +297,8 @@ class Cronks_Provider_CronksDataModel extends CronksBaseModel implements AgaviIS
             );
 
         }
-        $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;
     }
 





More information about the icinga-checkins mailing list