From fd52519fbb69d8fd71d4620ab92854869195a55d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 4 Oct 2010 12:55:52 -0600 Subject: [PATCH] Use transparent cache compression --- framework/Imap_Client/lib/Horde/Imap/Client.php | 10 ++-- .../Imap_Client/lib/Horde/Imap/Client/Cache.php | 59 ++++------------------ framework/Imap_Client/package.xml | 4 -- horde/config/conf.xml | 2 + imp/config/backends.php.dist | 11 ---- imp/lib/Imap.php | 1 - imp/scripts/query-imap-cache.php | 24 ++++----- 7 files changed, 26 insertions(+), 85 deletions(-) diff --git a/framework/Imap_Client/lib/Horde/Imap/Client.php b/framework/Imap_Client/lib/Horde/Imap/Client.php index 4b8099c7b..acea9ec74 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client.php @@ -115,13 +115,11 @@ class Horde_Imap_Client * * Optional Parameters: * -------------------- - * cache - (array) If set, caches data from fetch() calls. Requires - * Horde_Cache and Horde_Serialize to be installed. The array can - * contain the following keys (see Horde_Imap_Client_Cache:: for - * default values): + * cache - (array) If set, caches data from fetch() calls. Requires the + * horde/Cache package to be installed. The array can contain the + * following keys (see Horde_Imap_Client_Cache:: for default + * values): * cacheob - [REQUIRED] (Horde_Cache) The cache object to use. - * compress - [OPTIONAL] (string) Compression to use on the cached data. - * VALUES: false, 'gzip' or 'lzf'. * fields - [OPTIONAL] (array) The fetch criteria to cache. If not * defined, all cacheable data is cached. The following is a * list of criteria that can be cached: diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Cache.php b/framework/Imap_Client/lib/Horde/Imap/Client/Cache.php index d38a23310..ec87f17c6 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Cache.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Cache.php @@ -3,7 +3,7 @@ * Horde_Imap_Client_Cache:: provides an interface to cache various data * retrieved from the IMAP server. * - * Requires Horde_Cache and Horde_Serialize packages. + * Requires the horde/Cache package. * *
  * REQUIRED Parameters:
@@ -15,9 +15,6 @@
  *
  * Optional Parameters:
  * ====================
- * 'compress' - (string) Compression to use on the cached data.
- *              Either false, 'gzip' or 'lzf'.
- *              DEFAULT: No compression
  * 'debug' - (resource) If set, will output debug information to the stream
  *           identified.
  *           DEFAULT: No debug output
@@ -130,31 +127,9 @@ class Horde_Imap_Client_Cache
             'slicesize' => 50
         ), array_filter($params));
 
-        $compress = null;
-        if (!empty($params['compress'])) {
-            switch ($params['compress']) {
-            case 'gzip':
-                if (Horde_Serialize::hasCapability(Horde_Serialize::GZ_COMPRESS)) {
-                    $compress = Horde_Serialize::GZ_COMPRESS;
-                }
-                break;
-
-            case 'lzf':
-                if (Horde_Serialize::hasCapability(Horde_Serialize::LZF)) {
-                    $compress = Horde_Serialize::LZF;
-                }
-                break;
-            }
-
-            if (is_null($compress)) {
-                throw new InvalidArgumentException('Horde_Cache does not support the compression type given.');
-            }
-        }
-
         $this->_cache = $params['cacheob'];
 
         $this->_params = array(
-            'compress' => $compress,
             'debug' => $params['debug'],
             'hostspec' => $params['hostspec'],
             'lifetime' => intval($params['lifetime']),
@@ -169,7 +144,6 @@ class Horde_Imap_Client_Cache
      */
     public function __destruct()
     {
-        $compress = $this->_params['compress'];
         $lifetime = $this->_params['lifetime'];
 
         foreach ($this->_save as $mbox => $uids) {
@@ -182,11 +156,8 @@ class Horde_Imap_Client_Cache
 
                 /* Get the list of IDs to save. */
                 foreach (array_keys($sptr['slice'], $slice) as $uid) {
-                    /* Compress individual UID entries. We will worry about
-                     * error checking when decompressing (cache data will
-                     * automatically be invalidated then). */
                     if (isset($dptr[$uid])) {
-                        $data[$uid] = ($compress && is_array($dptr[$uid])) ? Horde_Serialize::serialize($dptr[$uid], array(Horde_Serialize::BASIC, $compress)) : $dptr[$uid];
+                        $data[$uid] = $dptr[$uid];
                     }
                 }
 
@@ -195,12 +166,12 @@ class Horde_Imap_Client_Cache
                     // If empty, we can expire the cache.
                     $this->_cache->expire($cid);
                 } else {
-                    $this->_cache->set($cid, Horde_Serialize::serialize($data, Horde_Serialize::BASIC), $lifetime);
+                    $this->_cache->set($cid, serialize($data), $lifetime);
                 }
             }
 
             // Save the slicemap
-            $this->_cache->set($this->_getCID($mbox, 'slicemap'), Horde_Serialize::serialize($sptr, Horde_Serialize::BASIC), $lifetime);
+            $this->_cache->set($this->_getCID($mbox, 'slicemap'), serialize($sptr), $lifetime);
         }
     }
 
@@ -468,7 +439,7 @@ class Horde_Imap_Client_Cache
             return;
         }
 
-        $data = Horde_Serialize::unserialize($data, Horde_Serialize::BASIC);
+        $data = @unserialize($data);
         if (!is_array($data)) {
             return;
         }
@@ -557,23 +528,15 @@ class Horde_Imap_Client_Cache
             return;
         }
 
-        $compress = $this->_params['compress'];
         $ptr = &$this->_data[$mailbox]['data'];
         $todelete = array();
 
         foreach ($uids as $val) {
-            if (isset($ptr[$val]) && !is_array($ptr[$val])) {
-                $success = false;
-                if (!is_null($compress)) {
-                    $res = Horde_Serialize::unserialize($ptr[$val], array($compress, Horde_Serialize::BASIC));
-                    if (!is_a($res, 'PEAR_Error')) {
-                        $ptr[$val] = $res;
-                        $success = true;
-                    }
-                }
-                if (!$success) {
-                    $todelete[] = $val;
-                }
+            if (isset($ptr[$val]) &&
+                ($res = @unserialize($ptr[$val]))) {
+                $ptr[$val] = $res;
+            } else {
+                $todelete[] = $val;
             }
         }
 
@@ -594,7 +557,7 @@ class Horde_Imap_Client_Cache
     {
         if (!isset($this->_slicemap[$mailbox])) {
             if (($data = $this->_cache->get($this->_getCID($mailbox, 'slicemap'), $this->_params['lifetime'])) !== false) {
-                $slice = Horde_Serialize::unserialize($data, Horde_Serialize::BASIC);
+                $slice = @unserialize($data);
                 if (is_array($slice)) {
                     $this->_slicemap[$mailbox] = $slice;
                 }
diff --git a/framework/Imap_Client/package.xml b/framework/Imap_Client/package.xml
index 96586af36..ef878f2a7 100644
--- a/framework/Imap_Client/package.xml
+++ b/framework/Imap_Client/package.xml
@@ -115,10 +115,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
     pear.horde.org
    
    
-     Serialize
-     pear.horde.org
-   
-   
     Stream_Filter
     pear.horde.org
    
diff --git a/horde/config/conf.xml b/horde/config/conf.xml
index 3884ea4e3..51dc33ed3 100644
--- a/horde/config/conf.xml
+++ b/horde/config/conf.xml
@@ -1046,6 +1046,8 @@
      
     
    
+   true