Skip to content

Commit

Permalink
Cache results of a bare Horde_Registry#getAuth() call
Browse files Browse the repository at this point in the history
Testing on the Ingo rule page, this results in ~3% speedup (44ms -> 9ms;
313 calls to getAuth() on my installation for this one request).
  • Loading branch information
slusarz committed Feb 5, 2014
1 parent 9081ab6 commit 57e39ed
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions framework/Core/lib/Horde/Registry.php
Expand Up @@ -130,6 +130,7 @@ class Horde_Registry implements Horde_Shutdown_Task
* @var array
*/
protected $_cache = array(
'auth' => null,
'conf' => array(),
'ob' => array()
);
Expand Down Expand Up @@ -1970,6 +1971,8 @@ public function clearAuth($destroy = true)
$session->remove('horde', 'auth');
$session->remove('horde', 'auth_app/');

$this->_cache['auth'] = null;

/* Remove the user's cached preferences if they are present. */
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->clearCache();

Expand Down Expand Up @@ -2201,6 +2204,10 @@ public function getAuth($format = null)
{
global $session;

if (is_null($format) && !is_null($this->_cache['auth'])) {
return $this->_cache['auth'];
}

if (!isset($session)) {
return false;
}
Expand Down Expand Up @@ -2228,6 +2235,9 @@ public function getAuth($format = null)
: substr($user, $pos + 1);

default:
/* Specifically cache this result, since it generally is called
* many times in a page. */
$this->_cache['auth'] = $user;
return $user;
}
}
Expand Down Expand Up @@ -2403,6 +2413,7 @@ public function setAuth($authId, $credentials, array $options = array())
}
$session->set('horde', 'auth/timestamp', time());
$session->set('horde', 'auth/userId', $this->convertUsername(trim($authId), true));
$this->_cache['auth'] = null;

$this->setAuthCredential($credentials, null, $app);

Expand Down

0 comments on commit 57e39ed

Please sign in to comment.