From b6319b43cf39afdc11b3edb667655545a9eb484e Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 10 Jun 2013 09:55:22 +0000 Subject: [PATCH] * 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 --- phpgwapi/inc/class.egw_cache.inc.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/phpgwapi/inc/class.egw_cache.inc.php b/phpgwapi/inc/class.egw_cache.inc.php index 886cc160f2..c9d7f723e0 100644 --- a/phpgwapi/inc/class.egw_cache.inc.php +++ b/phpgwapi/inc/class.egw_cache.inc.php @@ -7,7 +7,7 @@ * @package api * @subpackage cache * @author Ralf Becker - * @copyright (c) 2009-12 by Ralf Becker + * @copyright (c) 2009-13 by Ralf Becker * @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); } }