Prefix keys in RedisCacheSource
authorTim Düsterhus <duesterhus@woltlab.com>
Sun, 16 Oct 2016 17:18:17 +0000 (19:18 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 16 Oct 2016 17:20:38 +0000 (19:20 +0200)
The RedisCacheSource allows reusing the existing server
for other purposes. Prefixing the keys used by the cache
avoids accidental cache smashing by plugins.

wcfsetup/install/files/lib/system/cache/source/RedisCacheSource.class.php

index 92cdb763bd67777c135929aeb9bf7039fb5a7b91..d3ac80156fad6b9c212802f460a7df7249a15ce7 100644 (file)
@@ -58,10 +58,10 @@ class RedisCacheSource implements ICacheSource {
         */
        public function flushAll() {
                // set flush key to current time if it does not exist yet (this prevents falling back to 0 if the key gets deleted)
-               $this->redis->setnx('_flush', TIME_NOW);
+               $this->redis->setnx('cache:_flush', TIME_NOW);
                
                // atomic increment of flush count
-               $this->redis->incr('_flush');
+               $this->redis->incr('cache:_flush');
        }
        
        /**
@@ -141,17 +141,17 @@ class RedisCacheSource implements ICacheSource {
         * @return      string
         */
        protected function getCacheName($cacheName) {
-               $flush = $this->redis->get('_flush');
+               $flush = $this->redis->get('cache:_flush');
                
                // create flush counter if it does not exist
                if ($flush === false) {
-                       $this->redis->setnx('_flush', TIME_NOW);
-                       $this->redis->incr('_flush');
+                       $this->redis->setnx('cache:_flush', TIME_NOW);
+                       $this->redis->incr('cache:_flush');
                        
-                       $flush = $this->redis->get('_flush');
+                       $flush = $this->redis->get('cache:_flush');
                }
                
-               return $flush.':'.$cacheName;
+               return 'cache:'.$flush.':'.$cacheName;
        }
        
        /**