crodas/remember

Remember computations you did before (file cache)

v0.5.2 2018-07-05 03:30 UTC

This package is auto-updated.

Last update: 2024-12-12 19:31:53 UTC


README

Easiest way to remember things across requests in PHP.

Motivation

I love generating code and I needed a way of rebuilding only if something changed.

How it works

use Remember\Remember;

$function = Remember::wrap('name', function(Array $args, Array $files) {
    // do some that is expensive
    return $result;
});

// It will calculate once and cache the result
// until __FILE__ changes.
$result = $function([__FILE__, 'foobar']);

Low level API

use Remember\Remember;

$ns = Remember::ns('foobar');
$result = $ns->get([__FILE__], $isValid);
if (!$isValid) {
    // do something
    $result = ...;
    $ns->store([__FILE__], $result);
}