/** {@inheritdoc} */
 public function getResponse(RpcRequestInterface $request)
 {
     $key = $this->extractor->getKey($request);
     /** @var CacheItemInterface $item */
     $item = $this->items[$key]['item'];
     if ($item->isHit()) {
         return $item->get();
     }
     $item->expiresAfter($this->ttl);
     $item->set($this->proxiedCollection->getResponse($request));
     $this->cache->save($item);
     return $item->get();
 }
Exemplo n.º 2
0
 /** {@inheritdoc} */
 public function invoke($calls)
 {
     if (!is_array($calls)) {
         $calls = [$calls];
     }
     $items = [];
     $proxiedRequests = [];
     foreach ($calls as $call) {
         $key = $this->extractor->getKey($call);
         $item = $this->cache->getItem($key);
         $items[$key]['request'] = $call;
         $items[$key]['item'] = $item;
         if (!$item->isHit()) {
             $proxiedRequests[] = $call;
         }
     }
     // Prevent batch calls when not necessary
     if (count($proxiedRequests) === 1 && !is_array($calls)) {
         $proxiedRequests = array_shift($proxiedRequests);
     }
     return new CacheableResponseCollection($this->cache, $this->extractor, $items, $this->decoratedClient->invoke($proxiedRequests), $this->ttl);
 }