get rid of the cache global in ansel, use injector instead.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 27 May 2010 22:12:56 +0000 (18:12 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 27 May 2010 22:12:56 +0000 (18:12 -0400)
ansel/gallery.php
ansel/gallery/delete.php
ansel/lib/Application.php
ansel/lib/Faces/Base.php
ansel/lib/Gallery.php
ansel/lib/GalleryMode/Date.php
ansel/lib/GalleryMode/Normal.php
ansel/lib/Storage.php
ansel/lib/Tags.php
ansel/lib/Widget/OtherGalleries.php
ansel/rss.php

index 4d871da..ad4ab18 100644 (file)
@@ -273,7 +273,7 @@ case 'save':
 
     // Clear the OtherGalleries widget cache
     if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-        $GLOBALS['cache']->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
+        $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
     }
 
     // Return to the last view.
index e46b0a3..7a9f292 100644 (file)
@@ -45,7 +45,7 @@ if ($galleryId) {
 
         // Clear the OtherGalleries widget cache
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
         }
 
         // Return to the default view.
index 932dd56..f326051 100644 (file)
@@ -61,11 +61,6 @@ class Ansel_Application extends Horde_Registry_Application
             throw new Horde_Exception('You must configure a Horde_Image driver to use Ansel');
         }
 
-        // Create a cache object if we need it.
-        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache'] = $GLOBALS['injector']->getInstance('Horde_Cache');
-        }
-
         // Create db, share, and vfs instances.
         $GLOBALS['ansel_db'] = Ansel::getDb();
         $GLOBALS['ansel_storage'] = new Ansel_Storage();
index 9ba5293..104bef2 100644 (file)
@@ -587,7 +587,7 @@ class Ansel_Faces_Base
 
         // Expire gallery cache
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->expire('Ansel_Gallery' . $gallery->id);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
         }
 
         return $fids;
index 60aabc9..39353cc 100644 (file)
@@ -136,7 +136,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
         }
 
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->expire('Ansel_Gallery' . $this->id);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->id);
         }
 
         return parent::_save();
@@ -187,7 +187,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
         /* Need to expire the cache for the gallery that was changed */
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
             $id = (is_null($gallery_id) ? $this->id : $gallery_id);
-            $GLOBALS['cache']->expire('Ansel_Gallery' . $id);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $id);
         }
 
         return true;
@@ -933,7 +933,7 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
             $data = $this->_shareOb->_toDriverCharset(array($driver_key => $value));
             $query = $db->prepare('UPDATE ' . $this->_shareOb->getTable() . ' SET ' . $driver_key . ' = ? WHERE share_id = ?', null, MDB2_PREPARE_MANIP);
             if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-                $GLOBALS['cache']->expire('Ansel_Gallery' . $this->id);
+                $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->id);
             }
             $result = $query->execute(array($data[$driver_key], $this->id));
             $query->free();
index bf277f8..b624330 100644 (file)
@@ -459,8 +459,8 @@ class Ansel_GalleryMode_Date
 
         /* Expire the cache since we have no reason to save() the gallery */
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->expire('Ansel_Gallery' . $gallery->id);
-            $GLOBALS['cache']->expire('Ansel_Gallery' . $this->_gallery->id);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id);
         }
 
         return true;
index 4054cc8..0f1d76b 100644 (file)
@@ -203,8 +203,8 @@ class Ansel_GalleryMode_Normal {
 
         /* Expire the cache since we have no reason to save() the gallery */
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->expire('Ansel_Gallery' . $gallery->id);
-            $GLOBALS['cache']->expire('Ansel_Gallery' . $this->_gallery->id);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id);
         }
 
         return true;
index 621f097..a388ce0 100644 (file)
@@ -152,7 +152,7 @@ class Ansel_Storage
 
             /* Clear the parent from the cache */
             if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-                $GLOBALS['cache']->expire('Ansel_Gallery' . $parent);
+                $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $parent);
             }
         }
 
@@ -321,7 +321,7 @@ class Ansel_Storage
         }
 
        if (!count($overrides) && $GLOBALS['conf']['ansel_cache']['usecache'] &&
-           ($gallery = $GLOBALS['cache']->get('Ansel_Gallery' . $gallery_id, $GLOBALS['conf']['cache']['default_lifetime'])) !== false) {
+           ($gallery = $GLOBALS['injector']->getInstance('Horde_Cache')->get('Ansel_Gallery' . $gallery_id, $GLOBALS['conf']['cache']['default_lifetime'])) !== false) {
 
                $this->_galleries[$gallery_id] = unserialize($gallery);
 
@@ -338,7 +338,7 @@ class Ansel_Storage
        // Don't cache if we have overridden anything
        if (!count($overrides)) {
            if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-               $GLOBALS['cache']->set('Ansel_Gallery' . $gallery_id, serialize($result));
+               $GLOBALS['injector']->getInstance('Horde_Cache')->set('Ansel_Gallery' . $gallery_id, serialize($result));
            }
        } else {
            foreach ($overrides as $key => $value) {
@@ -410,7 +410,7 @@ class Ansel_Storage
 
         // Clear the OtherGalleries widget cache
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_OtherGalleries' . $gallery->get('owner'));
         }
     }
 
@@ -450,7 +450,7 @@ class Ansel_Storage
 
         /* Expire the cache */
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->expire('Ansel_Gallery' . $id);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $id);
         }
         unset($this->_galleries[$id]);
 
@@ -459,7 +459,7 @@ class Ansel_Storage
             if (!$parent->countChildren(Horde_Perms::SHOW, false)) {
                 $parent->set('has_subgalleries', 0, true);
                 if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-                    $GLOBALS['cache']->expire('Ansel_Gallery' . $parent->id);
+                    $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $parent->id);
                 }
                 unset($this->_galleries[$id]);
             }
index 40f795a..64c28a1 100644 (file)
@@ -135,9 +135,9 @@ class Ansel_Tags
         if (is_array($tags) && count($tags) == 0) {
             return array();
         }
-        if (isset($GLOBALS['cache'])) {
+        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
             $cache_key = 'ansel_taginfo_' . (!is_null($tags) ? md5(serialize($tags) . $limit) : $limit);
-            $cvalue = $GLOBALS['cache']->get($cache_key, $conf['cache']['default_lifetime']);
+            $cvalue = $GLOBALS['injector']->getInstance('Horde_Cache')->get($cache_key, $conf['cache']['default_lifetime']);
             if ($cvalue) {
                 return unserialize($cvalue);
             }
@@ -156,8 +156,8 @@ class Ansel_Tags
             $results[$id]['tag_name'] = Horde_String::convertCharset(
                 $taginfo['tag_name'], $GLOBALS['conf']['sql']['charset']);
         }
-        if (isset($GLOBALS['cache'])) {
-            $GLOBALS['cache']->set($cache_key, serialize($results));
+        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
+            $GLOBALS['injector']->getInstance('Horde_Cache')->set($cache_key, serialize($results));
         }
 
         return $results;
@@ -184,9 +184,9 @@ class Ansel_Tags
 
         $skey = md5(serialize($ids) . $from . $resource_type . $max . $user);
 
-        if (isset($GLOBALS['cache'])) {
+        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
            $key = Horde_Auth::getAuth() . '__anseltagsearches';
-           $cvalue = $GLOBALS['cache']->get($key, 300);
+           $cvalue = $GLOBALS['injector']->getInstance('Horde_Cache')->get($key, 300);
            $cvalue = @unserialize($cvalue);
            if (!$cvalue) {
                $cvalue = array();
@@ -260,9 +260,9 @@ class Ansel_Tags
             }
         }
 
-        if (isset($GLOBALS['cache'])) {
+        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
             $cvalue[$skey] = $results;
-            $GLOBALS['cache']->set($key, serialize($cvalue));
+            $GLOBALS['injector']->getInstance('Horde_Cache')->set($key, serialize($cvalue));
         }
 
         return $results;
@@ -448,7 +448,7 @@ class Ansel_Tags
     static public function clearCache()
     {
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->expire(Horde_Auth::getAuth() . '__anseltagsearches');
+            $GLOBALS['injector']->getInstance('Horde_Cache')->expire(Horde_Auth::getAuth() . '__anseltagsearches');
         }
     }
 }
index c3bf0c9..f75eab9 100644 (file)
@@ -39,13 +39,13 @@ class Ansel_Widget_OtherGalleries extends Ansel_Widget_Base
     public function html()
     {
         if ($GLOBALS['conf']['ansel_cache']['usecache'] &&
-            ($widget = $GLOBALS['cache']->get('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'))) !== false) {
+            ($widget = $GLOBALS['injector']->getInstance('Horde_Cache')->get('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'))) !== false) {
             return $widget;
         }
 
         $widget = $this->_htmlBegin() . $this->_getOtherGalleries() . $this->_htmlEnd();
         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['cache']->set('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'), $widget);
+            $GLOBALS['injector']->getInstance('Horde_Cache')->set('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'), $widget);
         }
 
         return $widget;
index 8ddff72..1f95e4e 100644 (file)
@@ -22,8 +22,8 @@ $uid = md5($stream_type . $id . $type . Horde_Auth::getAuth());
 $filename = 'ansel_feed_template_' . $uid;
 if ($conf['ansel_cache']['usecache']) {
     $cache_key = 'ansel_feed_template_' . $uid;
-    $rss = $cache->get($cache_key, $conf['cache']['default_lifetime']);
-    $filename = $cache->get($filename, $conf['cache']['default_lifetime']);
+    $rss = $GLOBALS['injector']->getInstance('Horde_Cache')->get($cache_key, $conf['cache']['default_lifetime']);
+    $filename = $GLOBALS['injector']->getInstance('Horde_Cache')->get($filename, $conf['cache']['default_lifetime']);
 }
 
 if (empty($rss)) {
@@ -290,8 +290,8 @@ if (empty($rss)) {
     $rss = ob_get_clean();
 
     if ($conf['ansel_cache']['usecache']) {
-        $cache->set($cache_key, $rss);
-        $cache->set($filename, $params['name']);
+        $GLOBALS['injector']->getInstance('Horde_Cache')->set($cache_key, $rss);
+        $GLOBALS['injector']->getInstance('Horde_Cache')->set($filename, $params['name']);
     }
 }