Merge pull request #6873 from nextcloud/ldap_proxy_redix_fix

Ldap proxy Redis fix
This commit is contained in:
Lukas Reschke 2017-10-19 12:03:04 +02:00 committed by GitHub
commit 9932b7498d
1 changed files with 12 additions and 19 deletions

View File

@ -65,7 +65,7 @@ abstract class Proxy {
static $db; static $db;
static $coreUserManager; static $coreUserManager;
static $coreNotificationManager; static $coreNotificationManager;
if(is_null($fs)) { if($fs === null) {
$ocConfig = \OC::$server->getConfig(); $ocConfig = \OC::$server->getConfig();
$fs = new FilesystemHelper(); $fs = new FilesystemHelper();
$log = new LogWrapper(); $log = new LogWrapper();
@ -158,7 +158,7 @@ abstract class Proxy {
*/ */
private function getCacheKey($key) { private function getCacheKey($key) {
$prefix = 'LDAP-Proxy-'; $prefix = 'LDAP-Proxy-';
if(is_null($key)) { if($key === null) {
return $prefix; return $prefix;
} }
return $prefix.md5($key); return $prefix.md5($key);
@ -169,24 +169,17 @@ abstract class Proxy {
* @return mixed|null * @return mixed|null
*/ */
public function getFromCache($key) { public function getFromCache($key) {
if(is_null($this->cache) || !$this->isCached($key)) { if($this->cache === null) {
return null; return null;
} }
$key = $this->getCacheKey($key); $key = $this->getCacheKey($key);
$value = $this->cache->get($key);
return json_decode(base64_decode($this->cache->get($key))); if ($value === null) {
} return null;
/**
* @param string $key
* @return bool
*/
public function isCached($key) {
if(is_null($this->cache)) {
return false;
} }
$key = $this->getCacheKey($key);
return $this->cache->hasKey($key); return json_decode(base64_decode($value));
} }
/** /**
@ -194,16 +187,16 @@ abstract class Proxy {
* @param mixed $value * @param mixed $value
*/ */
public function writeToCache($key, $value) { public function writeToCache($key, $value) {
if(is_null($this->cache)) { if($this->cache === null) {
return; return;
} }
$key = $this->getCacheKey($key); $key = $this->getCacheKey($key);
$value = base64_encode(json_encode($value)); $value = base64_encode(json_encode($value));
$this->cache->set($key, $value, '2592000'); $this->cache->set($key, $value, 2592000);
} }
public function clearCache() { public function clearCache() {
if(is_null($this->cache)) { if($this->cache === null) {
return; return;
} }
$this->cache->clear($this->getCacheKey(null)); $this->cache->clear($this->getCacheKey(null));