There is no license information available for the latest version (0.1.0) of this package.

Allows caching of methods in code.

0.1.0 2016-04-24 13:40 UTC

This package is not auto-updated.

Last update: 2020-02-07 17:13:51 UTC


What is this?

This library allows caching the result of methods for a specified amount of time. This can be on a global level or per user session.


Using composer:

composer require "genesis/method-persister"


namespace ABC\Example;

use Genesis\MethodPersister;

// Ideally done using a DI library.
$centralStoragePath = '/tmp/cache/';
$persistenceRepository = new MethodPersister\PersistenceRepository($centralStoragePath);
$persister = new MethodPersister\Persister($persistenceRepository);


Consider your code like this:

$result = $myObject->myMethod($arg1, $arg2);

return $result;

The above can be rewritten with the cacher as follows yielding the same but faster results.

$result = $persister->persist($myObject, 'myMethod')
	->withParameters($arg1, $arg2)
	->overAPeriodOf('+10 seconds')

// Use result as normal
return $result;

This will persist the cache for 10 seconds from the first call, after that the cache will be refreshed.


This project is in its early stages, forks are welcome :)


Library is tested using phpunit. To run tests first install dependencies using composer then run command:

phpunit -c tests