/** * Get the contents of a file. * * @param string $path * @return string * * @throws Exception */ public function get($path) { if ($this->isFile($path)) { return File::get($path); } throw new Exception("File does not exist at path {$path}"); }
private function cached($key, $value = null) { if (false === $this->cache) { return null; } $settings = isAke(self::$configs, $this->entity); $event = isAke($settings, 'cache'); if (!empty($event)) { return $this->{$event}($key, $value); } $file = STORAGE_PATH . DS . 'cache' . DS . $key . '.eav'; if (empty($value)) { if (File::exists($file)) { $age = filemtime($file); $maxAge = time() - $this->ttl; if ($maxAge < $age) { return json_decode(File::get($file), true); } else { File::delete($file); return null; } } } else { if (File::exists($file)) { File::delete($file); } File::put($file, json_encode($value)); return true; } }
public static function cache($type, $key, $data = null) { $settings = Arrays::exists($type, static::$_settings) ? static::$_settings[$type] : static::defaultConfig($type); $hook = Arrays::exists('cache', $settings) ? $settings['cache'] : null; static::_hook($hook, func_get_args(), 'before'); $dir = static::checkDir($type); $file = STORAGE_PATH . DS . 'data' . DS . $dir . DS . $key . '.cache'; if (File::exists($file)) { static::_hook($hook, func_get_args(), 'after'); return static::unserialize(gzuncompress(File::get($file))); } if (null !== $data) { File::put($file, gzcompress(static::serialize($data), -1)); static::_hook($hook, func_get_args(), 'after'); return true; } static::_hook($hook, func_get_args(), 'after'); return null; }