class Horde_Core_Factory_ThemesCache
{
/**
- * The list of cache IDs mapped to instance IDs.
- *
- * @var array
- */
- private $_cacheids = array();
-
- /**
* The injector.
*
* @var Horde_Injector
{
$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];
}
foreach ($this->_instances as $key => $val) {
if ($val->changed) {
- $cache->set($this->_cacheids[$key], serialize($val), 86400);
+ $cache->set($key, serialize($val), 86400);
}
}
}
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. */
/**
public function serialize()
{
return serialize(array(
+ $this->_getExpireId(),
$this->_app,
$this->_data,
$this->_theme
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');
+ }
}
}