Example #1
0
 /**
  * Store result of a query in cache.
  *
  * This method does not check if the target query has already been cached.
  * Use has() to prevent this issue.
  *
  * @param array $data Query result
  */
 public function set(array $data)
 {
     $hash = $this->reflector->getHash();
     $tags = $this->reflector->getTags();
     // Store data in cache
     $hash = $this->redis->prefix($hash);
     $this->redis->set($hash, $this->encodeData($data));
     // Add cache key to all tag sets
     // Thanks to this we can easily invalidate the data by tag afterwards
     foreach ($tags as $tag) {
         $this->redis->sadd($this->redis->prefix($tag), [$hash]);
     }
 }