using instance-wide cache for categories, so updates from other sessions are immediatly available and sessions get smaller

This commit is contained in:
Ralf Becker 2012-02-10 20:14:44 +00:00
parent f4f289011e
commit 56f286e877
2 changed files with 42 additions and 46 deletions

View File

@ -83,6 +83,8 @@ class categories
* @var array cat_id => array of data
*/
private static $cache;
const CACHE_APP = 'phpgwapi';
const CACHE_NAME = 'cat_cache';
/**
* Appname for global categories
@ -393,6 +395,8 @@ class categories
*/
static function read($id)
{
if (is_null(self::$cache)) self::init_cache();
if (!isset(self::$cache[$id])) return false;
$cat = self::$cache[$id];
@ -903,16 +907,13 @@ class categories
* Initialise or restore the categories cache
*
* We use the default ordering of return_array to avoid doing it again there
*
* @param array &$cache=null cache content to restore it (from the egw-object)
*/
public static function &init_cache(&$cache=null)
public static function init_cache()
{
if (!is_null($cache))
self::$cache = egw_cache::getInstance(self::CACHE_APP, self::CACHE_NAME);
if (is_null(self::$cache))
{
//error_log(__METHOD__."() ".count($cache)." cats restored: ".function_backtrace());
return self::$cache =& $cache;
}
// check if we are already updated to global owner == 0, if not do it now
if (!$GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',array('cat_owner'=>'0'),__LINE__,__FILE__)->fetchColumn())
{
@ -947,8 +948,9 @@ class categories
}
self::$cache[$cat['id']] = $cat;
}
egw_cache::setInstance(self::CACHE_APP, self::CACHE_NAME, self::$cache);
}
//error_log(__METHOD__."() cache initialised: ".function_backtrace());
return self::$cache;
}
/**
@ -961,9 +963,7 @@ class categories
*/
public static function invalidate_cache($cat_id=null)
{
self::init_cache();
// we need to invalidate the whole session cache, as it stores our cache
egw::invalidate_session_cache();
egw_cache::unsetInstance(self::CACHE_APP, self::CACHE_NAME);
}
/**
@ -981,6 +981,8 @@ class categories
*/
static function return_single($id)
{
if (is_null(self::$cache)) self::init_cache();
return isset(self::$cache[$id]) ? array(self::$cache[$id]) : false;
}

View File

@ -56,8 +56,6 @@ class egw extends egw_minimal
*/
var $hooks;
private $cat_cache;
/**
* Constructor: Instantiates the sub-classes
*
@ -181,8 +179,6 @@ class egw extends egw_minimal
$this->check_app_rights();
$this->load_optional_classes();
$this->cat_cache =& categories::init_cache();
}
else // set the defines for login, in case it's more then just login
{
@ -214,8 +210,6 @@ class egw extends egw_minimal
register_shutdown_function(array($this, 'shutdown'));
$this->define_egw_constants();
categories::init_cache($this->cat_cache);
}
/**