genesis/method-persister

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

README

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.

Installation

Using composer:

composer require "genesis/method-persister"

Instantiation

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

Usage

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')
	->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.

Contributions

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

Tests

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

phpunit -c tests