From 3a7129fa05bca85033db5cb55e5fae9dc0097862 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sun, 21 Dec 2014 02:54:15 +0100 Subject: [PATCH] Implement RedisCacheSource::set() --- .../cache/source/RedisCacheSource.class.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 a87216b77a..a1ee065cb0 100644 --- a/wcfsetup/install/files/lib/system/cache/source/RedisCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/RedisCacheSource.class.php @@ -83,10 +83,34 @@ class RedisCacheSource implements ICacheSource { } + /** + * Returns time to live in seconds, defaults to 3 days. + * + * @param integer $maxLifetime + * @return integer + */ + protected function getTTL($maxLifetime = 0) { + if ($maxLifetime) return $maxLifetime; + + // default to 3 days + return 60 * 60 * 24 * 3; + } + /** * @see \wcf\system\cache\source\ICacheSource::set() */ public function set($cacheName, $value, $maxLifetime) { + // split parameterized cache entry names into cache name and cache index + $parts = explode('-', $cacheName, 2); + // check if entry is parameterized + if (isset($parts[1])) { + // save parameterized cache entries as field in a hashset + $this->redis->hset($parts[0], $parts[1], serialize($value)); + } + else { + // save normal cache entries as simple key + $this->redis->setex($cacheName, $this->getTTL($maxLifetime), serialize($value)); + } } } -- 2.20.1