Skip to content

Commit

Permalink
[mms] Improved prefs caching.
Browse files Browse the repository at this point in the history
Use Horde_Core_Cache_Session to store data in the session, allowing for
offloading of data if it becomes too large.

Deprecate Horde_Core_Prefs_Cache_Session
  • Loading branch information
slusarz committed Dec 3, 2014
1 parent d246adc commit 297c714
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
52 changes: 48 additions & 4 deletions framework/Core/lib/Horde/Core/Factory/Prefs.php
Expand Up @@ -170,7 +170,7 @@ function_exists($params['user_hook'])) {
: array($config_driver, $hooks_driver);

if ($driver && $opts['cache']) {
$opts['cache'] = new Horde_Core_Prefs_Cache_Session($opts['user']);
$opts['cache'] = $this->_getCache($opts['user'], false);
} else {
unset($opts['cache']);
}
Expand All @@ -180,9 +180,15 @@ function_exists($params['user_hook'])) {
} catch (Horde_Prefs_Exception $e) {
$this->_notifyError($e);

/* Store data in the cached session object. */
$opts['cache'] = new Horde_Core_Prefs_Cache_Session($opts['user']);
$this->_instances[$sig] = new Horde_Prefs($scope, array($config_driver, $hooks_driver), $opts);
/* Store data in the cached session object. This cache data is
* stored for the life of the session. */
$opts['cache'] = $this->_getCache($opts['user'], true);

$this->_instances[$sig] = new Horde_Prefs(
$scope,
array($config_driver, $hooks_driver),
$opts
);
}

return $this->_instances[$sig];
Expand All @@ -205,6 +211,44 @@ protected function _notifyError($e)
}
}

/**
* Return the cache object to use for the prefs driver.
*
* @param string $user Username.
* @param boolean $fallback Return the fallback cache driver?
*
* @return Horde_Cache Cache object.
*/
protected function _getCache($user, $fallback)
{
global $injector;

$params = array(
'app' => 'horde',
'storage_key' => 'horde_prefs_cache'
);

if ($fallback) {
$params['cache'] = new Horde_Cache_Storage_Null();
$params['maxsize'] = 0;
} else {
$params['cache'] = $injector->getInstance('Horde_Cache');
}

return new Horde_Prefs_Cache_HordeCache(
$user,
array(
'cache' => new Horde_Cache(
new Horde_Core_Cache_Session($params),
array(
'compress' => true,
'logger' => $injector->getInstance('Horde_Core_Log_Wrapper')
)
)
)
);
}

/**
* Clear the instances cache.
*
Expand Down
12 changes: 7 additions & 5 deletions framework/Core/lib/Horde/Core/Prefs/Cache/Session.php
Expand Up @@ -14,11 +14,13 @@
/**
* Cache storage implementation using Horde_Session.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2010-2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2010-2014 Horde LLC
* @deprecated Use Horde_Prefs_Cache_HordeCache with the
* Horde_Core_Cache_Session driver instead.
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Core
*/
class Horde_Core_Prefs_Cache_Session extends Horde_Prefs_Cache_Base
{
Expand Down
4 changes: 2 additions & 2 deletions framework/Core/package.xml
Expand Up @@ -28,7 +28,7 @@
<email>mrubinsk@horde.org</email>
<active>yes</active>
</developer>
<date>2014-11-25</date>
<date>2014-12-03</date>
<version>
<release>2.17.2</release>
<api>2.17.0</api>
Expand Down Expand Up @@ -3739,7 +3739,7 @@
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2014-11-25</date>
<date>2014-12-03</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
Expand Down

0 comments on commit 297c714

Please sign in to comment.