Example #1
0
 /**
  * Get value from cache
  *
  * @param \Itkg\Core\CacheableInterface $item
  *
  * @return string
  */
 public function get(CacheableInterface $item)
 {
     if (false !== ($result = parent::get($item))) {
         return $result;
     }
     return $this->adapter->get($item);
 }
Example #2
0
 public function testGetSetCache()
 {
     $registry = new Registry();
     $eventDispatcher = new EventDispatcher();
     $eventDispatcher->addSubscriber(new CacheListener($eventDispatcher));
     $clientMock = $this->getMockBuilder('Itkg\\Consumer\\Client\\RestClient')->getMock();
     $clientMock->expects($this->once())->method('sendRequest');
     $cacheableService = new Service($eventDispatcher, $clientMock, array('identifier' => 'cacheable service', 'cache_serializer' => function (Response $response) {
         $response->setContent('My content');
         return serialize($response);
     }, 'cache_adapter' => $registry));
     $this->assertFalse($cacheableService->isLoaded());
     $cacheableService->sendRequest(Request::create('/'));
     $this->assertNotNull($registry->get($cacheableService));
     $cacheableService->sendRequest(Request::create('/'));
     $this->assertTrue($cacheableService->isLoaded());
 }