public function testGetData() { //Trying to get data we know is present $file_name = $this->getFileName(); setOutputDestination($file_name); $stamp = 'Laika, primul călător în cosmos'; file_put_contents($file_name, json_encode($stamp)); $data = $this->file_cache->getData($this->test_file_name); $this->assertEquals($stamp, $data); resetOutputDestination($file_name); //Trying to get data when the file is not there $data = $this->file_cache->getData($this->test_file_name); $this->assertFalse($data); }
/** * Instantiates object, sets session data */ public function __construct() { $cache = new FileCache(); $session = $cache->getData('session'); $this->data = $session; if (empty($session)) { $this->data = new \stdClass(); } self::$instance = $this; }
/** * Checks for new versions of Terminus once per week and saves to cache * * @param Logger $logger Logger to use to report result of check * @return void */ function checkForUpdate($logger) { $cache = new FileCache(); $cache_data = $cache->getData('latest_release', ['decode_array' => true]); if (!$cache_data || (int) $cache_data['check_date'] < (int) strtotime('-7 days')) { try { $current_version = checkCurrentVersion(); if (version_compare($current_version, TERMINUS_VERSION, '>')) { $logger->info('An update to Terminus is available. Please update to {version}.', ['version' => $current_version]); } } catch (\Exception $e) { $logger->info($e->getMessage()); $logger->info('Cannot retrieve current Terminus version.'); } } }
/** * Removes a site from the sites cache * * @param string $sitename Name of site to remove from array * @return void */ public function remove($sitename) { $cache = (array) $this->cache->getData($this->cachekey, array('decode_array' => true)); unset($cache[$sitename]); $this->cache->putData($this->cachekey, $cache); }