From: Maximilian Mader Date: Sun, 21 Dec 2014 01:54:15 +0000 (+0100) Subject: Implement RedisCacheSource::set() X-Git-Tag: 3.0.0_Beta_1~2305^2~6 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3a7129fa05bca85033db5cb55e5fae9dc0097862;p=GitHub%2FWoltLab%2FWCF.git Implement 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 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)); + } } }