/** * @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; }
/** * {@inheritdoc} */ public function add($key, $data, $ttl = 0) { $result = $this->cache->add($key, $data, $ttl); if ($result) { $this->hot[$key] = $data; } return $result; }
public function testAddNegative() { $result = $this->cache->add('test', 'test'); $this->assertTrue($result); $result = $this->cache->add('test', 'test2'); $this->assertFalse($result); $this->assertEquals('test', $this->cache->get('test')); $result = $this->cache->add('test', 'test2', 10); $this->assertFalse($result); $this->assertEquals('test', $this->cache->get('test')); }