示例#1
0
 public function testFlush()
 {
     $this->cache->set('test', 'data');
     $this->assertEquals('data', $this->cache->get('test'));
     $this->assertTrue($this->cache->flush());
     $this->assertFalse($this->cache->get('data'));
 }
示例#2
0
 /**
  * @param string $method
  * @param array $arguments
  * @return mixed
  * @throws \RuntimeException
  */
 public function __call($method, $arguments)
 {
     $reflection = new \ReflectionClass($this->decoratedObject);
     /*
      if (!$reflection->hasMethod($method)) {
          throw new \InvalidArgumentException('"' . $method . '" is not method of class ' . $reflection->name);
      }
     */
     $key = CacheProvider::generateCacheKey($reflection->name, $method, md5(var_export($arguments, true)));
     $result = $this->cache->get($key);
     if ($result === false) {
         $result = call_user_func_array([$this->decoratedObject, $method], $arguments);
         $this->cache->add($key, $result, $this->ttl);
     }
     return $result;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function add($key, $data, $ttl = 0)
 {
     $result = $this->cache->add($key, $data, $ttl);
     if ($result) {
         $this->hot[$key] = $data;
     }
     return $result;
 }