/** * @param string $method * @param array $params * @covers Fabfuel\Prophiler\Decorator\Phalcon\Cache\BackendDecorator * @dataProvider gatewayMethods */ public function testCallGatewayMethods($method, array $params) { $benchmark = $this->getMock('Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface'); $methodMock = $this->backend->expects($this->once())->method($method); call_user_func_array([$methodMock, 'with'], $params); $this->profiler->expects($this->once())->method('start')->with('CacheMock::' . $method, $params, 'Cache CacheMock')->willReturn($benchmark); $this->profiler->expects($this->once())->method('stop')->with($benchmark); call_user_func_array([$this->decorator, $method], $params); }
/** * Intercept a input http request * @param Request $request * @param array $params * @param CacheInterface $cache * @return bool Will return true if cache hit. */ protected function intercept(Request $request, array $params, CacheInterface $cache) { $ignores = $params['ignore_query_keys']; array_push($ignores, $this->timestampQueryKey); array_push($ignores, $params['jsonp_callback_key']); $debugQueryKey = $this->getDebugQueryKey(); array_push($ignores, $debugQueryKey); list($headersKey, $bodyKey) = $this->generateCacheKeys($request, $ignores); $hasCache = false; $headersCache = $bodyCache = ''; if (!$request->getQuery($debugQueryKey)) { $bodyCache = $cache->get($bodyKey); $headersCache = $cache->get($headersKey); $hasCache = $headersCache && $bodyCache; } else { // 要求刷新缓存时:先删了已有缓存,避免不正常退出时(如资源被移除)缓存未被刷新的情况。 $cache->delete($headersKey); } if ($hasCache) { /** * @var \Phalcon\Http\ResponseInterface $response */ $response = $request->getDI()->getResponse(); if ($headersCache) { //$headersCache = unserialize($headersCache); $headersCache = json_decode($headersCache); foreach ($headersCache as $key => $headerValue) { if (is_int($key)) { $response->setRawHeader($headerValue); } else { $response->setHeader($key, $headerValue); } } } $callbackKey = $params['jsonp_callback_key']; if ($params['format'] == 'jsonp' && $callbackKey && ($callbackValue = $request->getQuery($callbackKey))) { $bodyCache = $callbackValue . '(' . $bodyCache . ')'; } $response->setContent($bodyCache); return true; } // cache missing return false; }
/** * Destroy session handler * * @param string $id Session id * @return bool */ public function _destroy($id) { $this->backend->delete($id); return true; }