From ddb67a51eae2946e1c8c7228a84742d2f71ec881 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Sun, 2 Jan 2011 07:40:46 +0100 Subject: [PATCH] Start the caching layer. --- .../lib/Horde/Kolab/Storage/Decorator/Cache.php | 100 +++++++++++++++++++ .../Horde/Kolab/Storage/List/Decorator/Cache.php | 109 +++++++++++++++++++++ framework/Kolab_Storage/package.xml | 12 ++- .../Kolab/Storage/Unit/Decorator/CacheTest.php | 52 ++++++++++ 4 files changed, 270 insertions(+), 3 deletions(-) create mode 100644 framework/Kolab_Storage/lib/Horde/Kolab/Storage/Decorator/Cache.php create mode 100644 framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php create mode 100644 framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Decorator/CacheTest.php diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Decorator/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Decorator/Cache.php new file mode 100644 index 000000000..daa0987f2 --- /dev/null +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Decorator/Cache.php @@ -0,0 +1,100 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Storage + */ + +/** + * A cache decorator for the Kolab storage handler. + * + * Copyright 2004-2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Storage + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Storage + */ +class Horde_Kolab_Storage_Decorator_Cache +implements Horde_Kolab_Storage +{ + /** + * The decorated storage handler. + * + * @var Horde_Kolab_Storage + */ + private $_storage; + + /** + * The cache. + * + * @var Horde_Kolab_Storage_Cache + */ + private $_cache; + + /** + * Constructor. + * + * @param Horde_Kolab_Storage $storage The storage handler. + * @param Horde_Kolab_Storage_Cache $cache The cache. + */ + public function __construct( + Horde_Kolab_Storage $storage, + Horde_Kolab_Storage_Cache $cache + ) { + $this->_storage = $storage; + $this->_cache = $cache; + } + + /** + * Get the folder list object. + * + * @return Horde_Kolab_Storage_List The handler for the list of folders + * present in the Kolab backend. + */ + public function getList() + { + return new Horde_Kolab_Storage_List_Decorator_Cache( + $this->_storage->getList(), + $this->_cache + ); + } + + /** + * Get a Folder object. + * + * @param string $folder The folder name. + * + * @return Horde_Kolab_Storage_Folder The Kolab folder object. + */ + public function getFolder($folder) + { + return $this->_storage->getFolder(); + } + + /** + * Return a data handler for accessing data in the specified + * folder. + * + * @param string $folder The name of the folder. + * @param string $type The type of data we want to + * access in the folder. + * + * @return Horde_Kolab_Data The data object. + */ + public function getData($folder, $type) + { + return $this->_storage->getData(); + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..0c709f314 --- /dev/null +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Cache.php @@ -0,0 +1,109 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Storage + */ + +/** + * The cache decorator for folder lists from Kolab storage. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Storage + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Storage + */ +class Horde_Kolab_Storage_List_Decorator_Cache +implements Horde_Kolab_Storage_List +{ + /** + * Decorated list handler. + * + * @var Horde_Kolab_Storage_List + */ + private $_list; + + /** + * The cache. + * + * @var Horde_Kolab_Storage_Cache + */ + private $_cache; + + /** + * Constructor. + * + * @param Horde_Kolab_Storage_List $list The original list handler. + * @param Horde_Kolab_Storage_Cache $cache The cache storing data for this + * decorator. + */ + public function __construct( + Horde_Kolab_Storage_List $list, + Horde_Kolab_Storage_Cache $cache + ) { + $this->_list = $list; + $this->_cache = $cache; + } + + /** + * Returns the list of folders visible to the current user. + * + * @return array The list of folders, represented as a list of strings. + */ + public function listFolders() + { + $result = $this->_list->listFolders(); + return $result; + } + + /** + * Returns the folder types as associative array. + * + * @return array The list folder types with the folder names as key and the + * type as values. + */ + public function listTypes() + { + $result = $this->_list->listTypes(); + return $result; + } + + /** + * Returns the folder type annotation as associative array. + * + * @return array The list folder types with the folder names as key and the + * type handler as values. + */ + public function listFolderTypeAnnotations() + { + $result = $this->_list->listFolderTypeAnnotations(); + return $result; + } + + /** + * Return the specified query type. + * + * @param string $name The query name. + * + * @return Horde_Kolab_Storage_Query A query handler. + * + * @throws Horde_Kolab_Storage_Exception In case the requested query is not supported. + */ + public function getQuery($name) + { + return $this->_list->getQueryWithParent($name, $this); + } + +} \ No newline at end of file diff --git a/framework/Kolab_Storage/package.xml b/framework/Kolab_Storage/package.xml index c43be12ad..f449f61de 100644 --- a/framework/Kolab_Storage/package.xml +++ b/framework/Kolab_Storage/package.xml @@ -31,8 +31,8 @@ jan@horde.org yes - 2010-12-28 - + 2011-01-02 + 0.4.0 0.1.0 @@ -74,6 +74,7 @@ + @@ -137,6 +138,7 @@ + @@ -433,6 +435,7 @@ + @@ -572,6 +575,7 @@ + @@ -613,6 +617,7 @@ + @@ -719,6 +724,7 @@ + @@ -802,7 +808,7 @@ alpha alpha - 2010-12-28 + 2011-01-02 LGPL * Added namespace support (Bug #6691). diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Decorator/CacheTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Decorator/CacheTest.php new file mode 100644 index 000000000..80e84dafd --- /dev/null +++ b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Decorator/CacheTest.php @@ -0,0 +1,52 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Storage + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../../Autoload.php'; + +/** + * Test the cache decorator for the storage handler. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Kolab + * @package Kolab_Storage + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Storage + */ +class Horde_Kolab_Storage_Unit_Decorator_CacheTest +extends Horde_Kolab_Storage_TestCase +{ + public function testDecoratedList() + { + $storage = new Horde_Kolab_Storage_Decorator_Cache( + new Horde_Kolab_Storage_Base( + $this->getNullMock(), + new Horde_Kolab_Storage_Factory() + ), + new Horde_Kolab_Storage_Cache(null) + ); + $this->assertInstanceOf( + 'Horde_Kolab_Storage_List_Decorator_Cache', + $storage->getList() + ); + } +} -- 2.11.0