/** * Constructor. * * If the filter finds an existing cache entry for the given request, then it loads it and sets "stopRoute" to true. * @todo Add \Niysu\Services\ResourcesCacheService for third parameter */ public function __construct(\Niysu\HTTPRequestInterface $request, \Niysu\HTTPResponseInterface $response, $resourcesCacheService, &$stopRoute, \Monolog\Logger $log = null) { $this->outputResponse = $response; $this->request = $request; $this->responseStorage = new \Niysu\HTTPResponseStorage(); $this->cacheService = $resourcesCacheService; $this->log = $log; if ($request->getMethod() == 'GET') { $this->writeInCache = true; $this->transmitToParent = true; $this->ttl = 300; // 5mn // attempting to load from cache if ($loadedData = $resourcesCacheService->load($request->getURL(), $request->getHeadersList())) { $this->writeInCache = false; $this->transmitToParent = false; $fp = \Niysu\HTTPResponseStream::build($this->getOutput(), true); $fp->fwrite($loadedData); $stopRoute = true; } } else { $this->writeInCache = false; $this->transmitToParent = true; } }