From 3d4149105a121c9f161a1c3dde1b4cd1be6e0a31 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Mon, 3 Jan 2011 22:34:31 +0100 Subject: [PATCH] Store one list array in the cache. --- .../lib/Horde/Kolab/Storage/Cache.php | 14 ++-- .../lib/Horde/Kolab/Storage/Cache/List.php | 90 ++++++++++++---------- .../Storage/Unit/List/Decorator/CacheTest.php | 3 +- 3 files changed, 56 insertions(+), 51 deletions(-) diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php index b0c2f2589..de4811797 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php @@ -177,27 +177,25 @@ 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) + public function loadListData($connection_id) { - return $this->horde_cache->get($this->_getListKey($connection_id, $key), 0); + return $this->horde_cache->get($this->_getListKey($connection_id), 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) + public function storeListData($connection_id, $data) { - $this->horde_cache->set($this->_getListKey($connection_id, $key), $data); + $this->horde_cache->set($this->_getListKey($connection_id), $data); } /** @@ -208,9 +206,9 @@ class Horde_Kolab_Storage_Cache * * @return mixed The data of the object. */ - private function _getListKey($connection_id, $key) + private function _getListKey($connection_id) { - return $connection_id . ':LIST:' . $key; + return $connection_id . ':LIST'; } /** 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 449a65dc3..408d0ffa3 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache/List.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache/List.php @@ -60,6 +60,13 @@ class Horde_Kolab_Storage_Cache_List private $_list_id; /** + * The list data. + * + * @var array + */ + private $_data = false; + + /** * Constructor. * * @param Horde_Kolab_Storage_Cache $cache The core cache driver. @@ -83,23 +90,50 @@ class Horde_Kolab_Storage_Cache_List } /** + * Retrieve list data. + * + * @param string $key Access key to the cached data. + * + * @return mixed The data of the object. + */ + private function _load($key) + { + $data = $this->_cache->loadListData($this->_list_id); + if (isset($data[$key])) { + return $data[$key]; + } + } + + /** + * Store list data. + * + * @param string $key Access key to the cached data. + * @param mixed $data Value to cache. + * + * @return NULL + */ + private function _store($key, $data) + { + $stored = $this->_cache->loadListData($this->_list_id); + if (!is_array($stored)) { + $stored = array(); + } + $stored[$key] = $data; + $this->_cache->storeListData($this->_list_id, $stored); + } + + /** * Check if the cache has been initialized. * * @return boolean True if cache data is available. */ public function isInitialized() { - $last_sync = $this->_cache->loadListData( - $this->_list_id, - self::SYNC - ); + $last_sync = $this->_load(self::SYNC); if (empty($last_sync)) { return false; } - $version = $this->_cache->loadListData( - $this->_list_id, - self::VERSION - ); + $version = $this->_load(self::VERSION); if ($version != self::FORMAT_VERSION) { return false; } @@ -113,10 +147,7 @@ class Horde_Kolab_Storage_Cache_List */ public function getFolders() { - return $this->_cache->loadListData( - $this->_list_id, - self::FOLDERS - ); + return $this->_load(self::FOLDERS); } /** @@ -127,10 +158,7 @@ class Horde_Kolab_Storage_Cache_List */ public function getFolderTypes() { - return $this->_cache->loadListData( - $this->_list_id, - self::TYPES - ); + return $this->_load(self::TYPES); } /** @@ -140,30 +168,10 @@ class Horde_Kolab_Storage_Cache_List */ public function store(array $folders = null, array $types = null) { - $this->_cache->storeListData( - $this->_list_id, - self::QUERIES, - array() - ); - $this->_cache->storeListData( - $this->_list_id, - self::FOLDERS, - $folders - ); - $this->_cache->storeListData( - $this->_list_id, - self::TYPES, - $types - ); - $this->_cache->storeListData( - $this->_list_id, - self::VERSION, - self::FORMAT_VERSION - ); - $this->_cache->storeListData( - $this->_list_id, - self::SYNC, - time() - ); + $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()); } } diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/CacheTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/CacheTest.php index b9d218d67..1ad9366f1 100644 --- a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/CacheTest.php +++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Decorator/CacheTest.php @@ -276,8 +276,7 @@ extends Horde_Kolab_Storage_TestCase $cache ) ); - $cache->storeListData($list->getConnectionId(), 'S', time()); - $cache->storeListData($list->getConnectionId(), 'V', '1'); + $cache->storeListData($list->getConnectionId(), array('S' => time(), 'V' => '1')); $this->mockDriver->expects($this->never()) ->method('getMailboxes') ->will($this->returnValue(array('INBOX'))); -- 2.11.0