Skip to content
A library to cache methods.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
LICENSE.md
README.md
composer.json
composer.lock

README.md

Method Persister/Cacher Codeship Status for forceedge01/method-cacher

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
You can’t perform that action at this time.