Mecha CMS

Cache::live()

Update cache value automatically every time the expiration period is reached.

2.2.0Static

Cache::live(string $id, callable $fn, string $for = '1 day');
Cache::live(string $id, callable $fn, int $for = 86400);

Example:

$cache = Cache::live('foo', function() {
    return date('Y-m-d H:i:s');
}, '1 day');

$cache = Cache::live('.\path\to\file.php', function($file) {
    ob_start();
    require $file;
    return ob_get_clean();
}, '1 day');