felixmaier1989/soft-cache

为您的类方法提供软缓存

0.2 2017-10-04 05:53 UTC

This package is auto-updated.

Last update: 2024-09-04 19:58:53 UTC


README

为您的类方法提供软缓存。有时,在脚本运行过程中,某个方法可能会用相同的参数执行多次。最好是缓存其输出,尤其是在查询数据库或API时。

用法

class TestClass {

	use SoftCache\SoftCacheTrait;

	public function getNextYearsWithCache($yearFrom, $years) {
		if ($this->checkMethodCache(__FUNCTION__, func_get_args())) {
			return $this->readMethodCache(__FUNCTION__, func_get_args());
		}
		$output = $this->getNextYearsWithoutCache($yearFrom, $years);
		$this->writeMethodCache(__FUNCTION__, func_get_args(), $output);
		return $output;
	}

	public function getNextYearsWithoutCache($yearFrom, $years) {
		return range($yearFrom + 1 , $yearFrom + $years);
	}

}