Share code for session cache key calculation

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2016-12-13 11:17:58 +01:00
parent 8d5939348e
commit 2b134240b8

View File

@ -2964,6 +2964,20 @@ class Util
self::cacheUnset('is_grantuser');
}
/**
* Calculates session cache key
*
* @return string
*/
public static function cacheKey()
{
if (isset($GLOBALS['cfg']['Server']['user'])) {
return 'server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user'];
} else {
return 'server_' . $GLOBALS['server'];
}
}
/**
* Verifies if something is cached in the session
*
@ -2973,7 +2987,7 @@ class Util
*/
public static function cacheExists($var)
{
return isset($_SESSION['cache']['server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']][$var]);
return isset($_SESSION['cache'][self::cacheKey()][$var]);
}
/**
@ -2987,7 +3001,7 @@ class Util
public static function cacheGet($var, $callback = null)
{
if (self::cacheExists($var)) {
return $_SESSION['cache']['server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']][$var];
return $_SESSION['cache'][self::cacheKey()][$var];
} else {
if ($callback) {
$val = $callback();
@ -3008,7 +3022,7 @@ class Util
*/
public static function cacheSet($var, $val = null)
{
$_SESSION['cache']['server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']][$var] = $val;
$_SESSION['cache'][self::cacheKey()][$var] = $val;
}
/**
@ -3020,7 +3034,7 @@ class Util
*/
public static function cacheUnset($var)
{
unset($_SESSION['cache']['server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']][$var]);
unset($_SESSION['cache'][self::cacheKey()][$var]);
}
/**