Imbo\EventListener\MetadataCache::storeInCache PHP Method

storeInCache() public method

Store metadata in the cache
public storeInCache ( Imbo\EventManager\EventInterface $event )
$event Imbo\EventManager\EventInterface The event instance
    public function storeInCache(EventInterface $event)
    {
        $request = $event->getRequest();
        $response = $event->getResponse();
        $cacheKey = $this->getCacheKey($request->getUser(), $request->getImageIdentifier());
        // Store the response in the cache for later use
        if ($response->getStatusCode() === 200) {
            $metadata = [];
            if ($model = $response->getModel()) {
                $metadata = $model->getData();
            }
            $this->cache->set($cacheKey, ['lastModified' => $response->getLastModified(), 'metadata' => $metadata]);
        }
    }

Usage Example

Beispiel #1
0
 /**
  * @covers Imbo\EventListener\MetadataCache::storeInCache
  */
 public function testDoesNotStoreDataInCacheWhenResponseCodeIsNot200()
 {
     $this->cache->expects($this->never())->method('set');
     $this->response->expects($this->once())->method('getStatusCode')->will($this->returnValue(404));
     $this->listener->storeInCache($this->event);
 }