Simplify caching the list data.
authorGunnar Wrobel <p@rdus.de>
Mon, 3 Jan 2011 21:50:43 +0000 (22:50 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 4 Jan 2011 07:54:26 +0000 (08:54 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache/List.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/CacheTest.php

index 217535d..15d5517 100644 (file)
@@ -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();
     }
 }
index 83546ec..4f7946d 100644 (file)
@@ -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
index 4204bd7..e582c1c 100644 (file)
@@ -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'));
     }
 
     /**