* API: allow to set a maximum caching time used instead of unlimited caching or a bigger time, eg. in header.inc.php: egw_caching::$max_expiration = 864000; // 10days

This commit is contained in:
Ralf Becker 2013-06-10 09:55:22 +00:00
parent 7fd4199cba
commit b6319b43cf

View File

@ -7,7 +7,7 @@
* @package api
* @subpackage cache
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2009-12 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2009-13 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @version $Id$
*/
@ -73,6 +73,13 @@ class egw_cache
*/
static $default_provider; // = array('egw_cache_files');// array('egw_cache_memcache','localhost');
/**
* Maximum expiration time, if set unlimited expiration (=0) or bigger expiration times are replaced with that time
*
* @var int
*/
static $max_expiration;
/**
* Set some data in the cache
*
@ -98,6 +105,11 @@ class egw_cache
{
return false;
}
// limit expiration to configured maximum time
if (isset(self::$max_expiration) && (!$expiration || $expiration > self::$max_expiration))
{
$expiration = self::$max_expiration;
}
return $provider->set(self::keys($level,$app,$location),$data,$expiration);
}
throw new egw_exception_wrong_parameter(__METHOD__."() unknown level '$level'!");
@ -160,6 +172,11 @@ class egw_cache
if (is_null($data) && !is_null($callback))
{
$data = call_user_func_array($callback,$callback_params);
// limit expiration to configured maximum time
if (isset(self::$max_expiration) && (!$expiration || $expiration > self::$max_expiration))
{
$expiration = self::$max_expiration;
}
$provider->set($keys,$data,$expiration);
}
}