diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2012-07-26 16:11:23 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2012-07-26 16:11:32 +0200 |
commit | 6c92a85d49822dba180fe949d211db60c5b40d51 (patch) | |
tree | 1a1eed9ddaf006b91122cb7b61ceebe9ba83182e /apps/user_ldap/lib | |
parent | e0121ea75e85db681b4c7e50aa73b0b519c4d989 (diff) | |
download | nextcloud-server-6c92a85d49822dba180fe949d211db60c5b40d51.tar.gz nextcloud-server-6c92a85d49822dba180fe949d211db60c5b40d51.zip |
LDAP: use OC_Cache to cache results from LDAP. Default is set to 10 min. Should improve performance especially when LDAP users use the sync client, because userExists checks with the LDAP server are reduced.
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/connection.php | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index 96ffea4b64b..cd9c83ff333 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -28,7 +28,10 @@ class Connection { private $configID; private $configured = false; - //cached settings + //cache handler + protected $cache; + + //settings protected $config = array( 'ldapHost' => null, 'ldapPort' => null, @@ -48,10 +51,12 @@ class Connection { 'ldapQuotaAttribute' => null, 'ldapQuotaDefault' => null, 'ldapEmailAttribute' => null, + 'ldapCacheTTL' => null, ); public function __construct($configID = 'user_ldap') { $this->configID = $configID; + $this->cache = \OC_Cache::getGlobalCache(); } public function __destruct() { @@ -92,6 +97,57 @@ class Connection { return $this->ldapConnectionRes; } + private function getCacheKey($key) { + $prefix = 'LDAP-'.$this->configID.'-'; + if(is_null($key)) { + return $prefix; + } + return $prefix.md5($key); + } + + public function getFromCache($key) { + if(!$this->configured) { + $this->readConfiguration(); + } + if(!$this->config['ldapCacheTTL']) { + return null; + } + if(!$this->isCached($key)) { + return null; + + } + $key = $this->getCacheKey($key); + + return unserialize(base64_decode($this->cache->get($key))); + } + + public function isCached($key) { + if(!$this->configured) { + $this->readConfiguration(); + } + if(!$this->config['ldapCacheTTL']) { + return false; + } + $key = $this->getCacheKey($key); + return $this->cache->hasKey($key); + } + + public function writeToCache($key, $value) { + if(!$this->configured) { + $this->readConfiguration(); + } + if(!$this->config['ldapCacheTTL']) { + return null; + } + $key = $this->getCacheKey($key); + $value = base64_encode(serialize($value)); + $this->cache->set($key, $value, $this->config['ldapCacheTTL']); + } + + public function clearCache() { + $this->cache->clear($this->getCacheKey(null)); + } + /** * Caches the general LDAP configuration. */ @@ -118,6 +174,7 @@ class Connection { $this->config['ldapEmailAttribute'] = \OCP\Config::getAppValue($this->configID, 'ldap_email_attr', ''); $this->config['ldapGroupMemberAssocAttr'] = \OCP\Config::getAppValue($this->configID, 'ldap_group_member_assoc_attribute', 'uniqueMember'); $this->config['ldapIgnoreNamingRules'] = \OCP\Config::getSystemValue('ldapIgnoreNamingRules', false); + $this->config['ldapCacheTTL'] = \OCP\Config::getAppValue($this->configID, 'ldap_cache_ttl', 10*60); $this->configured = $this->validateConfiguration(); } |