Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function __construct($config = [])
 {
     $this->parentConstruct($config);
     if ($this->cache instanceof CacheInterface) {
         $this->cache->save();
         $this->adapter = new CachedAdapter($this->adapter, $this->cache);
     }
     parent::__construct($this->adapter, $this->config);
     $this->addPlugin(new ListPaths());
     $this->addPlugin(new ListWith());
     $this->addPlugin(new GetWithMetadata());
 }
 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);
 }
 /**
  * Configure after successful mount.
  *
  * @return void
  **/
 protected function configure()
 {
     parent::configure();
     if ($this->fscache && $this->isMyReload()) {
         $this->fscache->flush();
     }
 }
Esempio n. 4
0
 /**
  * {@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;
 }
Esempio n. 5
0
 /**
  * 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;
 }