From: Michael M Slusarz Date: Tue, 23 Nov 2010 20:18:39 +0000 (-0700) Subject: Move cache invalidation to Horde_Themes_Cache X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a600660db8e28ae50d794e6de4a9bd6875243c7f;p=horde.git Move cache invalidation to Horde_Themes_Cache --- diff --git a/framework/Core/lib/Horde/Core/Factory/ThemesCache.php b/framework/Core/lib/Horde/Core/Factory/ThemesCache.php index d00efac46..e90f86e51 100644 --- a/framework/Core/lib/Horde/Core/Factory/ThemesCache.php +++ b/framework/Core/lib/Horde/Core/Factory/ThemesCache.php @@ -28,13 +28,6 @@ class Horde_Core_Factory_ThemesCache { /** - * The list of cache IDs mapped to instance IDs. - * - * @var array - */ - private $_cacheids = array(); - - /** * The injector. * * @var Horde_Injector @@ -70,44 +63,33 @@ class Horde_Core_Factory_ThemesCache { $sig = implode('|', array($app, $theme)); - if (isset($this->_instances[$sig])) { - return $this->_instances[$sig]; - } - - if (!empty($GLOBALS['conf']['cachethemes'])) { - $cache = $this->_injector->getInstance('Horde_Cache'); - } - - if (!$cache || ($cache instanceof Horde_Cache_Null)) { - $instance = new Horde_Themes_Cache($app, $theme); - } else { - $id = $sig . '|' . $GLOBALS['registry']->getVersion($app); - if ($app != 'horde') { - $id .= '|' . $GLOBALS['registry']->getVersion('horde'); - } - - $cache_sig = hash('md5', $id); - - try { - $instance = @unserialize($cache->get($cache_sig, 86400)); - } catch (Exception $e) { - $instance = null; + if (!isset($this->_instances[$sig])) { + if (!empty($GLOBALS['conf']['cachethemes'])) { + $cache = $this->_injector->getInstance('Horde_Cache'); } - if (!($instance instanceof Horde_Themes_Cache)) { + if (!$cache || ($cache instanceof Horde_Cache_Null)) { $instance = new Horde_Themes_Cache($app, $theme); - $instance->build(); + } else { + try { + $instance = @unserialize($cache->get($sig, 86400)); + } catch (Exception $e) { + $instance = null; + } + + if (!($instance instanceof Horde_Themes_Cache)) { + $instance = new Horde_Themes_Cache($app, $theme); + $instance->build(); + } - if (empty($this->_cacheids)) { + if (empty($this->_instances)) { register_shutdown_function(array($this, 'shutdown')); } } - $this->_cacheids[$sig] = $cache_sig; + $this->_instances[$sig] = $instance; } - $this->_instances[$sig] = $instance; - return $this->_instances[$sig]; } @@ -120,7 +102,7 @@ class Horde_Core_Factory_ThemesCache foreach ($this->_instances as $key => $val) { if ($val->changed) { - $cache->set($this->_cacheids[$key], serialize($val), 86400); + $cache->set($key, serialize($val), 86400); } } } diff --git a/framework/Core/lib/Horde/Themes/Cache.php b/framework/Core/lib/Horde/Themes/Cache.php index 3294b1447..5e732af95 100644 --- a/framework/Core/lib/Horde/Themes/Cache.php +++ b/framework/Core/lib/Horde/Themes/Cache.php @@ -207,6 +207,18 @@ class Horde_Themes_Cache implements Serializable return $out; } + /** + */ + protected function _getExpireId() + { + $id = array($GLOBALS['registry']->getVersion($this->_app)); + if ($this->_app != 'horde') { + $id[] = $GLOBALS['registry']->getVersion('horde'); + } + + return 'v:' . implode('|', $id); + } + /* Serializable methods. */ /** @@ -214,6 +226,7 @@ class Horde_Themes_Cache implements Serializable public function serialize() { return serialize(array( + $this->_getExpireId(), $this->_app, $this->_data, $this->_theme @@ -225,10 +238,15 @@ class Horde_Themes_Cache implements Serializable public function unserialize($data) { list( + $expire_id, $this->_app, $this->_data, $this->_theme ) = unserialize($data); + + if ($expire_id != $this->_getExpireId()) { + throw new Exception('Cache invalidated'); + } } }