dev-master
9999999-devAllows caching of methods in code.
The Development Requires
0.1.0
0.1.0.0Allows caching of methods in code.
The Development Requires
Wallogit.com
2017 © Pedro Peláez
Allows caching of methods in code.
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., (*1)
Using composer:, (*2)
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:, (*3)
$result = $myObject->myMethod($arg1, $arg2); return $result;
The above can be rewritten with the cacher as follows yielding the same but faster results., (*4)
$result = $persister->persist($myObject, 'myMethod')
->withParameters($arg1, $arg2)
->overAPeriodOf('+10 seconds')
->execute();
// 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. The default storage method is centralised but can be changed to distributed i.e session caching using the ->in() method., (*5)
$result = $persister->persist($myObject, 'userSpecificData')
->withParameters($arg1, $arg2)
->overAPeriodOf('+10 seconds')
->in(PersisterInterface::STATE_DISTRIBUTE)
->execute();
This project is in its early stages, forks are welcome :), (*6)
Library is tested using phpunit. To run tests first install dependencies using composer then run command:, (*7)
make
Allows caching of methods in code.
Allows caching of methods in code.