The Horde_Kolab_Storage_Cache singleton instance provides caching for all
storage folders. So before operating on the cache data it is necessary to
load the desired folder data. Before switching the folder the cache data
should be saved.
This class does not offer a lot of safeties and is primarily intended to be
used within the Horde_Kolab_Storage_Data class.
Copyright 2007-2016 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If you
did not receive this file, see http://www.horde.org/licenses/lgpl21.
private function _getQuery($data) { $cache = new Horde_Kolab_Storage_Cache($this->_cache); $data_cache = $cache->getDataCache($data->getIdParameters()); $params = array('cache' => $data_cache); return new Horde_Kolab_Storage_Data_Query_Preferences_Cache($data, $params); }
/** * Stores the objects list in the cache. * * @param array $object The object data to store. * @param Horde_Kolab_Storage_Folder_Stamp $stamp The current stamp. * @param string $version The format version of * the provided data. * @param array $delete Backend IDs that were * removed. */ public function store(array $objects, Horde_Kolab_Storage_Folder_Stamp $stamp, $version, array $delete = array()) { $this->_load(); if (!empty($delete)) { foreach ($delete as $obid => $object_id) { $object = $this->_data[self::OBJECTS][$object_id]; if (!empty($object['_attachments'])) { // @todo clean up attachment formatting mess. if (isset($object['_attachments']['id'])) { $ids = $object['_attachments']['id']; } else { $ids = array_keys($object['_attachments']); } foreach ($ids as $id) { $this->_cache->deleteAttachment($this->getDataId(), $obid, $id); } } unset($this->_data[self::O2B][$object_id]); unset($this->_data[self::OBJECTS][$object_id]); unset($this->_data[self::B2O][$obid]); } } foreach ($objects as $obid => $object) { if (!empty($object) && isset($object['uid'])) { if (isset($this->_data[self::O2B][$object['uid']])) { if (!isset($this->_data[self::DUPLICATES][$object['uid']])) { $this->_data[self::DUPLICATES][$object['uid']][] = $this->_data[self::O2B][$object['uid']]; } $this->_data[self::DUPLICATES][$object['uid']][] = $obid; } $this->_data[self::B2O][$obid] = $object['uid']; $this->_data[self::O2B][$object['uid']] = $obid; if (isset($object['_attachments'])) { $attachments = array(); foreach ($object['_attachments'] as $id => $attachment) { $attachments['id'][] = $id; if (isset($attachment['name'])) { $attachments['name'][$attachment['name']][] = $id; } if (isset($attachment['type'])) { $attachments['type'][$attachment['type']][] = $id; } $this->_cache->storeAttachment($this->getDataId(), $obid, $id, $attachment['content']); } $object['_attachments'] = $attachments; } $this->_data[self::OBJECTS][$object['uid']] = $object; } else { $this->_data[self::B2O][$obid] = false; $this->_data[self::ERRORS][] = $obid; } } $this->_data[self::QUERIES] = array(); $this->_data[self::STAMP] = serialize($stamp); $this->_data[self::DATA_VERSION] = $version; $this->_data[self::VERSION] = self::FORMAT_VERSION; $this->_data[self::ID] = serialize($this->_parameters); $this->_data[self::SYNC] = time(); }
/** * Constructor. * * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the * data from. * @param Horde_Kolab_Storage_Driver $driver The primary connection driver. * @param Horde_Kolab_Storage_Factory $factory The factory. * @param Horde_Kolab_Storage_Cache $cache The cache storing data for * this decorator. * @param string $type The type of data we want to * access in the folder. * @param int $version Format version of the object * data. */ public function __construct(Horde_Kolab_Storage_Folder $folder, Horde_Kolab_Storage_Driver $driver, Horde_Kolab_Storage_Factory $factory, Horde_Kolab_Storage_Cache $cache, $type = null, $version = 1) { parent::__construct($folder, $driver, $factory, $type, $version); $this->_data_cache = $cache->getDataCache($this->getIdParameters()); }
/** * Cache the list data. * * @return NULL */ public function save() { $this->_cache->storeList($this->getListId(), serialize($this->_data)); }
/** * Stores the objects list in the cache. * * @param array $object The object data to store. * @param Horde_Kolab_Storage_Folder_Stamp $stamp The current stamp. * @param string $version The format version of * the provided data. * @param array $delete Backend IDs that were * removed. */ public function store(array $objects, Horde_Kolab_Storage_Folder_Stamp $stamp, $version, array $delete = array()) { $this->_load(); if (!empty($delete)) { foreach ($delete as $obid => $object_id) { $object = $this->_data[self::OBJECTS][$object_id]; // Check if the delete request is for the last version of an object. // Otherwise the removal of a duplicate might remove the // current version of an object. $cached_obid = $this->_data[self::O2B][$object_id]; if ($cached_obid == $obid) { if (!empty($object['_attachments'])) { // @todo clean up attachment formatting mess. if (isset($object['_attachments']['id'])) { $ids = $object['_attachments']['id']; } else { $ids = array_keys($object['_attachments']); } foreach ($ids as $id) { $this->_cache->deleteAttachment($this->getDataId(), $obid, $id); } } unset($this->_data[self::O2B][$object_id]); unset($this->_data[self::OBJECTS][$object_id]); } else { Horde::log(sprintf("[KOLAB_STORAGE] Keeping object %s" . " with uid %d, duplicate object with uid %d was removed", $object_id, $cached_obid, $obid), 'DEBUG'); } unset($this->_data[self::B2O][$obid]); } } foreach ($objects as $obid => $object) { if (!empty($object) && isset($object['uid'])) { if (isset($this->_data[self::O2B][$object['uid']])) { if (!isset($this->_data[self::DUPLICATES][$object['uid']])) { $this->_data[self::DUPLICATES][$object['uid']][] = $this->_data[self::O2B][$object['uid']]; } $this->_data[self::DUPLICATES][$object['uid']][] = $obid; } $this->_data[self::B2O][$obid] = $object['uid']; $this->_data[self::O2B][$object['uid']] = $obid; if (isset($object['_attachments'])) { $attachments = array(); foreach ($object['_attachments'] as $id => $attachment) { $attachments['id'][] = $id; if (isset($attachment['name'])) { $attachments['name'][$attachment['name']][] = $id; } if (isset($attachment['type'])) { $attachments['type'][$attachment['type']][] = $id; } $this->_cache->storeAttachment($this->getDataId(), $obid, $id, $attachment['content']); } $object['_attachments'] = $attachments; } $this->_data[self::OBJECTS][$object['uid']] = $object; } else { $this->_data[self::B2O][$obid] = false; $this->_data[self::ERRORS][] = $obid; } } $this->_data[self::QUERIES] = array(); $this->_data[self::STAMP] = serialize($stamp); $this->_data[self::DATA_VERSION] = $version; $this->_data[self::VERSION] = self::FORMAT_VERSION; $this->_data[self::ID] = serialize($this->_parameters); $this->_data[self::SYNC] = time(); }
/** * Fetch any additional parameters required when creating data queries. * * @param Horde_Kolab_Storage_Data $data The data. * * @return array The parameters for data queries. */ protected function _getDataQueryParameters(Horde_Kolab_Storage_Data $data) { return array('cache' => $this->_cache->getDataCache($data->getIdParameters())); }