protected function make_it_cache_getter($method, $path, $response) { $this->cache->{$method}($path)->willReturn(false); $this->adapter->{$method}($path)->willReturn($response); $this->cache->updateObject($path, $response, true)->shouldBeCalled(); $this->{$method}($path)->shouldBe($response); }
/** * {@inheritdoc} */ public function getImageInfo($path) { // If cache doesn't support image info, just pass through to adapter. if (!$this->cache instanceof Capability\ImageInfo) { return $this->doGetImageInfo($path); } // Get from cache. $info = $this->cache->getImageInfo($path); if ($info !== false) { return is_array($info) ? Image\Info::createFromJson($info) : $info; } // Else from adapter. $info = $this->doGetImageInfo($path); // Save info from adapter. $object = ['path' => $path, 'image_info' => $info]; $this->cache->updateObject($path, $object, true); return $info; }
/** * Call a method and cache the response. * * @param string $method * @param string $path * * @return mixed */ protected function callWithFallback($method, $path) { $result = $this->cache->{$method}($path); if ($result !== false) { return $result; } $result = $this->adapter->{$method}($path); if ($result) { $object = $result + compact('path'); $this->cache->updateObject($path, $object, true); } return $result; }