/** * @return AircraftCollection */ public function getAllAircraft() { if ($this->cacheEnabled) { $cacheItem = $this->cachePool->getItem('aircraftCollection'); $aircraftCollection = $cacheItem->get(); if ($cacheItem->isHit()) { return $aircraftCollection; } } $fileObjects = $this->recursiveIterator; $aircraftCollection = $this->aircraftCollection; foreach ($fileObjects as $file) { if ($file->getFilename() === 'aircraft.json') { $json = file_get_contents($file->getPathName()); if ($json) { $aircraftConfig = json_decode($json); $aircraftConfig->path = $file->getPath(); $aircraftCollection->push($aircraftConfig); } } } if ($this->cacheEnabled) { $this->cachePool->save($cacheItem->set($aircraftCollection)); } return $aircraftCollection; }
/** @inheritDoc */ public function get($key, callable $callback) { assert(is_string($key) || is_int($key)); $item = $this->stash->getItem((string) $key); $result = $item->get(); if ($item->isMiss()) { $item->lock(); $result = call_user_func($callback); $this->stash->save($item->set($result)); } return $result; }
public function testConstruction() { $key = array('apple', 'sauce'); $driver = new Sqlite(array()); $pool = new Pool(); $pool->setDriver($driver); $item = $pool->getItem('testKey'); $item->set($key); $this->assertTrue($pool->save($item), 'Able to load and store with unconfigured extension.'); }
public function save(CacheItemInterface $item) { $this->pool->save($item); }