/** * Fetches stored value by key. * * @param string $key Cache key. * * @access public * * @return mixed */ public function fetch($key) { $file = self::storagePath() . self::generateName($key); $expire = null; $value = null; try { $content = File::getContents($file); if ($content) { list($expire, $value) = json_decode($content, true); } } catch (\Exception $e) { return null; } if ($expire && $expire < time()) { try { File::delete($file); } catch (\Exception $e) { // Provide comment why we are not processing the catched exception. } return null; } return $value; }
/** * @covers Core\Helpers\File::getContents */ public function testGettingContents() { $this->assertStringEqualsFile(Core\Config()->paths('root') . $this->baseName, File::getContents($this->baseName)); }