bnomei/kirby3-lapse

Cache any data until set expiration time

Installs: 108

Dependents: 0

Suggesters: 0

Stars: 2

Watchers: 0

Forks: 0

Open Issues: 1

Type:kirby-plugin

1.1.1 2019-02-05 23:26 UTC

README

GitHub release License Kirby Version Kirby 3 Pluginkit

Cache any data until set expiration time.

Commercial Usage

This plugin is free but if you use it in a commercial project please consider to

Installation

  • unzip master.zip as folder site/plugins/kirby3-lapse or
  • git submodule add https://github.com/bnomei/kirby3-lapse.git site/plugins/kirby3-lapse or
  • composer require bnomei/kirby3-lapse

Usage Examples

Example 1: get/set

$key = md($page->url()); // unique key
// to delay data creation until need use a callback. do not use a plain array or object.
$data = function () {
    return [1, 2, 3];
}
// Bnomei\Lapse::lapse() or just lapse()
$data = lapse($key, $data);

Example 2: with custom expiration time

// EXPIRE
// if ommited config settings apply
$expires = 5; // in minutes. 
$data = lapse($key, $data, $expires);

Example 3: without the variables

// compressed code
$data = lapse(md($page->url()), function () use ($kirby, $site, $page) {
    // create some data. could be array, could be object, anything really.
    return [
        'title' => $page->title()->value(),
        'url' => $page->url(),
    ];
}, 5);

Parameter: force

$force = true;
$data = lapse($key, $data, $expires, $force);

Tip 1: devalidate on page modification

$key = md5($page->id().$page->modified());
$data = lapse($key, $data);

Tip 2: flush cache

Bnomei\Lapse::flush();

Settings

All settings need bnomei.lapse. as prefix.

expires default: 60*24 in minutes

This Plugin uses minutes not seconds since K3 Cache does that as well. So be carefull in that regard when migrating from Jens' plugin.

debugforce default: true force refresh if Kirbys global debug options is active

field-as-object default: false will call $field->value() and store string instead of serializied object.

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

License

MIT

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.

Credits

based on V2 version of