Allow to cache list data.
authorGunnar Wrobel <p@rdus.de>
Mon, 3 Jan 2011 06:32:02 +0000 (07:32 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 4 Jan 2011 07:54:20 +0000 (08:54 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/CacheTest.php

index 71b4319..b0c2f25 100644 (file)
@@ -174,6 +174,46 @@ class Horde_Kolab_Storage_Cache
     }
 
     /**
+     * Retrieve list data.
+     *
+     * @param string $connection_id ID of the connection matching the list.
+     * @param string $key           Access key to the cached data.
+     *
+     * @return mixed The data of the object.
+     */
+    public function loadListData($connection_id, $key)
+    {
+        return $this->horde_cache->get($this->_getListKey($connection_id, $key), 0);
+    }
+
+    /**
+     * Cache list data.
+     *
+     * @param string $connection_id ID of the connection matching the list.
+     * @param string $key           Access key to the cached data.
+     * @param string $data          The data to be cached.
+     *
+     * @return boolean True if successfull.
+     */
+    public function storeListData($connection_id, $key, $data)
+    {
+        $this->horde_cache->set($this->_getListKey($connection_id, $key), $data);
+    }
+
+    /**
+     * Retrieve list data.
+     *
+     * @param string $connection_id ID of the connection matching the list.
+     * @param string $key           Access key to the cached data.
+     *
+     * @return mixed The data of the object.
+     */
+    private function _getListKey($connection_id, $key)
+    {
+        return $connection_id . ':LIST:' . $key;
+    }
+
+    /**
      * Load a cached attachment.
      *
      * @param string $key Access key to the cached data.
index 44ea0bb..905ce92 100644 (file)
@@ -82,22 +82,36 @@ class Horde_Kolab_Storage_CacheTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(false, $cache->uids[11]);
     }
 
-    /**
-     * Test storing/loading attachments.
-     *
-     * @return NULL
-     */
-    public function testAttachments()
+    public function testLoadAttachment()
     {
         $cache = new Horde_Kolab_Storage_Cache($this->cache);
         $cache->storeAttachment('a', 'attachment');
         $this->assertEquals('attachment', $cache->loadAttachment('a'));
+    }
+
+    public function testLoadSecondAttachment()
+    {
+        $cache = new Horde_Kolab_Storage_Cache($this->cache);
+        $cache->storeAttachment('a', 'attachment');
         $cache->storeAttachment('b', 'b');
         $this->assertEquals('b', $cache->loadAttachment('b'));
+    }
+
+    public function testOverrideAttachment()
+    {
+        $cache = new Horde_Kolab_Storage_Cache($this->cache);
+        $cache->storeAttachment('a', 'attachment');
         $cache->storeAttachment('a', 'a');
         $this->assertEquals('a', $cache->loadAttachment('a'));
     }
 
+    public function testCachingListData()
+    {
+        $cache = new Horde_Kolab_Storage_Cache($this->cache);
+        $cache->storeListData('user@example.com:143', 'folders', array('a', 'b'));
+        $this->assertEquals(array('a', 'b'), $cache->loadListData('user@example.com:143', 'folders'));
+    }
+
     /**
      * Test loading/saving the cache.
      *