Don't do mtime checking in Horde_Themes_Css
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 23 Nov 2010 21:06:26 +0000 (14:06 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 23 Nov 2010 22:47:19 +0000 (15:47 -0700)
framework/Core/lib/Horde/Themes/Cache.php
framework/Core/lib/Horde/Themes/Css.php

index 52ee5af..0473e5c 100644 (file)
@@ -36,6 +36,13 @@ class Horde_Themes_Cache implements Serializable
     protected $_app;
 
     /**
+     * The cache ID.
+     *
+     * @var string
+     */
+    protected $_cacheid;
+
+    /**
      * Theme data.
      *
      * @var array
@@ -209,20 +216,26 @@ class Horde_Themes_Cache implements Serializable
 
     /**
      */
-    protected function _getExpireId()
+    public function getCacheId()
     {
-        switch ($GLOBALS['config']['themescacheparams']['check']) {
-        case 'appversion':
-        default:
-            $id = array($GLOBALS['registry']->getVersion($this->_app));
-            if ($this->_app != 'horde') {
-                $id[] = $GLOBALS['registry']->getVersion('horde');
-            }
-            return 'v:' . implode('|', $id);
+        if (!isset($this->_cacheid)) {
+            switch ($GLOBALS['config']['themescacheparams']['check']) {
+            case 'appversion':
+            default:
+                $id = array($GLOBALS['registry']->getVersion($this->_app));
+                if ($this->_app != 'horde') {
+                    $id[] = $GLOBALS['registry']->getVersion('horde');
+                }
+                $this->_cacheid = 'v:' . implode('|', $id);
+                break;
 
-        case 'none':
-            return '';
+            case 'none':
+                $this->_cacheid = '';
+                break;
+            }
         }
+
+        return $this->_cacheid;
     }
 
     /* Serializable methods. */
@@ -232,7 +245,7 @@ class Horde_Themes_Cache implements Serializable
     public function serialize()
     {
         return serialize(array(
-            $this->_getExpireId(),
+            $this->getCacheId(),
             $this->_app,
             $this->_data,
             $this->_theme
@@ -250,7 +263,7 @@ class Horde_Themes_Cache implements Serializable
             $this->_theme
         ) = unserialize($data);
 
-        if ($expire_id && ($expire_id != $this->_getExpireId())) {
+        if ($expire_id && ($expire_id != $this->getCacheId())) {
             throw new Exception('Cache invalidated');
         }
     }
index d82138c..b027996 100644 (file)
 class Horde_Themes_Css
 {
     /**
+     * The theme cache ID.
+     *
+     * @var string
+     */
+    protected $_cacheid;
+
+    /**
      * A list of additional stylesheet files to add to the output.
      *
      * @var array
@@ -54,7 +61,7 @@ class Horde_Themes_Css
      * Generate the stylesheet URLs needed to display the current page.
      * Honors configuration choices as to stylesheet caching.
      *
-     * @param array $options  Additional options:
+     * @param array $opts  Additional options:
      * <pre>
      * 'nohorde' - (boolean) If true, don't load files from Horde.
      * 'sub' - (string) A subdirectory containing additional CSS files to
@@ -67,14 +74,17 @@ class Horde_Themes_Css
      *
      * @return array  The list of URLs to display.
      */
-    public function getStylesheetUrls($options = array())
+    public function getStylesheetUrls(array $opts = array())
     {
         global $conf, $injector, $prefs, $registry;
 
         $themesfs = $registry->get('themesfs');
         $themesuri = $registry->get('themesuri');
 
-        $css = $this->getStylesheets(isset($options['theme']) ? $options['theme'] : $prefs->getValue('theme'), $options);
+        $theme = isset($opts['theme'])
+            ? $opts['theme']
+            : $prefs->getValue('theme');
+        $css = $this->getStylesheets($theme, $opts);
 
         $cache_type = empty($conf['cachecss'])
             ? 'none'
@@ -88,14 +98,8 @@ class Horde_Themes_Css
             return $css_out;
         }
 
-        $mtime = array(0);
         $out = '';
-
-        foreach ($css as $file) {
-            $mtime[] = filemtime($file['fs']);
-        }
-
-        $sig = hash('md5', serialize($css) . max($mtime));
+        $sig = hash('md5', serialize($css) . $this->_cacheid);
 
         switch ($cache_type) {
         case 'filesystem':
@@ -188,6 +192,7 @@ class Horde_Themes_Css
             : $opts['sub'];
 
         $build = $GLOBALS['injector']->getInstance('Horde_Core_Factory_ThemesCache')->create($curr_app, $theme);
+        $this->_cacheid = $build->getCacheId();
 
         foreach ($css_list as $css_name) {
             if (empty($opts['subonly'])) {