5 use Consolidation\AnnotatedCommand\Cache\SimpleCacheInterface;
8 * Command cache implementation.
10 * This wrapper implements a cache usable with the annotated-command
11 * library's command cache. It uses a Drush JSONCache for its back-end.
13 class CommandCache implements SimpleCacheInterface
16 protected $cacheBackend;
18 public function __construct(CacheInterface $cacheBackend)
20 $this->cacheBackend = $cacheBackend;
24 * Test for an entry from the cache
28 public function has($key)
30 $cacheItem = $this->cacheBackend->get($key);
31 return $this->valid($cacheItem);
34 * Get an entry from the cache
38 public function get($key)
40 $cacheItem = $this->cacheBackend->get($key);
41 if (!$this->valid($cacheItem)) {
44 // TODO: FileCache::get() should just return the
45 // data element, not the entire cacheItem. Then we
46 // could make it implement SimpleCacheInterface & do
47 // away with this adapter class.
48 return $cacheItem->data;
51 * Store an entry in the cache
55 public function set($key, $data)
57 $this->cacheBackend->set($key, $data);
60 protected function valid($cacheItem)
62 return is_object($cacheItem) && isset($cacheItem->data);