From 2f15443cd153ae770ba9ecc4a2668473f6030c7e Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Mon, 3 Jan 2011 22:50:43 +0100 Subject: [PATCH] Simplify caching the list data. --- .../lib/Horde/Kolab/Storage/Cache/List.php | 28 ++++++++++------------ .../Horde/Kolab/Storage/List/Decorator/Cache.php | 2 ++ .../test/Horde/Kolab/Storage/Unit/CacheTest.php | 4 ++-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache/List.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache/List.php index 217535d17..15d5517a9 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache/List.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache/List.php @@ -98,25 +98,20 @@ class Horde_Kolab_Storage_Cache_List { if ($this->_data === false) { $this->_data = $this->_cache->loadListData($this->_list_id); + if (!is_array($this->_data)) { + $this->_data = array(); + } } } /** - * Store list data. - * - * @param string $key Access key to the cached data. - * @param mixed $data Value to cache. + * Cache the list data. * * @return NULL */ - private function _store($key, $data) + public function save() { - $stored = $this->_cache->loadListData($this->_list_id); - if (!is_array($stored)) { - $stored = array(); - } - $stored[$key] = $data; - $this->_cache->storeListData($this->_list_id, $stored); + $this->_cache->storeListData($this->_list_id, $this->_data); } /** @@ -169,10 +164,11 @@ class Horde_Kolab_Storage_Cache_List */ public function store(array $folders = null, array $types = null) { - $this->_store(self::QUERIES, array()); - $this->_store(self::FOLDERS, $folders); - $this->_store(self::TYPES, $types); - $this->_store(self::VERSION, self::FORMAT_VERSION); - $this->_store(self::SYNC, time()); + $this->_load(); + $this->_data[self::QUERIES] = array(); + $this->_data[self::FOLDERS] = $folders; + $this->_data[self::TYPES] = $types; + $this->_data[self::VERSION] = self::FORMAT_VERSION; + $this->_data[self::SYNC] = time(); } } diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php index 83546ec9b..4f7946de0 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php @@ -127,6 +127,8 @@ implements Horde_Kolab_Storage_List $this->_list->listFolderTypes() ); + $this->_list_cache->save(); + $this->_init = true; } } \ No newline at end of file diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CacheTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CacheTest.php index 4204bd704..e582c1cb3 100644 --- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CacheTest.php +++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CacheTest.php @@ -109,8 +109,8 @@ extends Horde_Kolab_Storage_TestCase 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')); + $cache->storeListData('user@example.com:143', array('folders' => array('a', 'b'))); + $this->assertEquals(array('folders' => array('a', 'b')), $cache->loadListData('user@example.com:143')); } /** -- 2.11.0