Search by

felixmaier1989 / soft-cache

felixmaier1989

Soft cache for your class methods

Package info

github.com/felixmaier1989/soft-cache

pkg:composer/felixmaier1989/soft-cache

Statistics

Installs: 51 208

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

0.2 2017-10-04 05:53 UTC

This package is auto-updated.

Last update: 2026-09-05 00:43:27 UTC


README

Soft cache for your class methods. Sometimes, during one script run, one method is executed several times with the same arguments. Better caching the output of it, especially when querying a databse or an API.

Usage

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);
	}

}