From: Maximilian Mader Date: Wed, 31 Dec 2014 16:01:30 +0000 (+0100) Subject: Improve RedisCacheSource::set() X-Git-Tag: 3.0.0_Beta_1~2305^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1be236ed1f3596a9b9a76e06af73ce5941a45e48;p=GitHub%2FWoltLab%2FWCF.git Improve RedisCacheSource::set() --- diff --git a/wcfsetup/install/files/lib/system/cache/source/RedisCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/RedisCacheSource.class.php index b12c578503..e9ec4c7b99 100644 --- a/wcfsetup/install/files/lib/system/cache/source/RedisCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/RedisCacheSource.class.php @@ -124,12 +124,23 @@ class RedisCacheSource implements ICacheSource { // check if entry is parameterized if (isset($parts[1])) { + $key = $this->getCacheName($parts[0]); + // save parameterized cache entries as field in a hashset - $this->redis->hset($parts[0], $parts[1], serialize($value)); + // saving in a hashset is safe as the smallest lifetime of its fields is set as TTL for the whole hashset + $this->redis->hset($key, $parts[1], serialize($value)); + + $keyTTL = $this->redis->ttl($key); + $newTTL = $this->getTTL($maxLifetime); + + // set a new TTL if no TTL is set or if the current TTL is longer than the new one. + if ($keyTTL < 0 || $keyTTL > $newTTL) { + $this->redis->expire($key, $newTTL); + } } else { // save normal cache entries as simple key - $this->redis->setex($cacheName, $this->getTTL($maxLifetime), serialize($value)); + $this->redis->setex($this->getCacheName($cacheName), $this->getTTL($maxLifetime), serialize($value)); } }