From 7b6dae17da09e4e7de22144fe4cd82c185320b6a Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Mon, 3 Jan 2011 07:32:02 +0100 Subject: [PATCH] Allow to cache list data. --- .../lib/Horde/Kolab/Storage/Cache.php | 40 ++++++++++++++++++++++ .../test/Horde/Kolab/Storage/CacheTest.php | 26 ++++++++++---- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php index 71b4319da..b0c2f2589 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php @@ -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. diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/CacheTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/CacheTest.php index 44ea0bbb7..905ce92b5 100644 --- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/CacheTest.php +++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/CacheTest.php @@ -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. * -- 2.11.0