From 1be236ed1f3596a9b9a76e06af73ce5941a45e48 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Wed, 31 Dec 2014 17:01:30 +0100 Subject: [PATCH] Improve RedisCacheSource::set() --- .../cache/source/RedisCacheSource.class.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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)); } } -- 2.20.1