PHPackages                             bnomei/kirby3-lapse - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. bnomei/kirby3-lapse

AbandonedArchivedKirby-plugin[Caching](/categories/caching)

bnomei/kirby3-lapse
===================

Cache any data until set expiration time

5.0.0(1y ago)212.7k↑100%[1 PRs](https://github.com/bnomei/kirby3-lapse/pulls)MITPHPPHP &gt;=8.2

Since Aug 31Pushed 1y ago2 watchersCompare

[ Source](https://github.com/bnomei/kirby3-lapse)[ Packagist](https://packagist.org/packages/bnomei/kirby3-lapse)[ RSS](/packages/bnomei-kirby3-lapse/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (43)Used By (0)

> ARCHIVED MAY 2025. suggested alternative:
>
> # Kirby Lapse
>
> [](#kirby-lapse)

[![Kirby 5](https://camo.githubusercontent.com/b1a1b2ccd58e96259a9722c2489d91f40378c01b6c4c3e9fd27ed1d12c269d7c/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f4b697262792f353f636f6c6f723d454343373438)](https://getkirby.com)[![PHP 8.2](https://camo.githubusercontent.com/fd050028b4459f3f6e4db5703412957375ceb180d27951213d421eb2a23c8c8e/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f5048502f382e323f636f6c6f723d3445354239332669636f6e3d706870266c6162656c)](https://camo.githubusercontent.com/fd050028b4459f3f6e4db5703412957375ceb180d27951213d421eb2a23c8c8e/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f5048502f382e323f636f6c6f723d3445354239332669636f6e3d706870266c6162656c)[![Release](https://camo.githubusercontent.com/5432924310446f862fa9dd2d8a3dc89bb54c49cde9a61ab744d8a2302df48c81/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f762f626e6f6d65692f6b69726279332d6c617073653f636f6c6f723d6165383166662669636f6e3d676974687562266c6162656c)](https://camo.githubusercontent.com/5432924310446f862fa9dd2d8a3dc89bb54c49cde9a61ab744d8a2302df48c81/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f762f626e6f6d65692f6b69726279332d6c617073653f636f6c6f723d6165383166662669636f6e3d676974687562266c6162656c)[![Downloads](https://camo.githubusercontent.com/3d410bff36445435049e463ef82b7e10f89a7d9d6d5b8be5061254f3da64b587/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f64742f626e6f6d65692f6b69726279332d6c617073653f636f6c6f723d3237323832322669636f6e3d676974687562266c6162656c)](https://camo.githubusercontent.com/3d410bff36445435049e463ef82b7e10f89a7d9d6d5b8be5061254f3da64b587/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f64742f626e6f6d65692f6b69726279332d6c617073653f636f6c6f723d3237323832322669636f6e3d676974687562266c6162656c)[![Coverage](https://camo.githubusercontent.com/e534c64fc63187a4a5c982aee243a51327c01520598953cf6647adff74efba84/68747470733a2f2f666c61742e62616467656e2e6e65742f636f6465636c696d6174652f636f7665726167652f626e6f6d65692f6b69726279332d6c617073653f69636f6e3d636f6465636c696d617465266c6162656c)](https://codeclimate.com/github/bnomei/kirby3-lapse)[![Maintainability](https://camo.githubusercontent.com/e03ed6bd4bc7998910eaddcbf919da9368098c0524aea41446217fcd1c19a880/68747470733a2f2f666c61742e62616467656e2e6e65742f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f626e6f6d65692f6b69726279332d6c617073653f69636f6e3d636f6465636c696d617465266c6162656c)](https://codeclimate.com/github/bnomei/kirby3-lapse/issues)[![Discord](https://camo.githubusercontent.com/36eaef1b06f4996feb7587aa3281dcbd658e57535bc6b5e10110ed108e7a7a03/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f646973636f72642f626e6f6d65693f636f6c6f723d3732383964612669636f6e3d646973636f7264266c6162656c)](https://discordapp.com/users/bnomei)[![Buymecoffee](https://camo.githubusercontent.com/62e55d1129b82bf9c2fd4656451e81ab87a9787e7c9676ca58276532ed9666ee/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f69636f6e2f646f6e6174653f69636f6e3d6275796d6561636f6666656526636f6c6f723d464638313346266c6162656c)](https://www.buymeacoffee.com/bnomei)

Cache any data until set expiration time (with automatic keys).

Installation
------------

[](#installation)

- unzip [master.zip](https://github.com/bnomei/kirby3-lapse/archive/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`

Usecase
-------

[](#usecase)

The Kirby Pages-Cache can cache the output of Page Templates. It invalidates **all** cache files if any Object in the Panel is changed. This is a good choice if you do not make changes often. But if you do make changes often you need a cache that knows what has been modified and which caches to devalidate and which not.

Sometimes you can not cache the complete Page since...

- it contains a [form](https://github.com/mzur/kirby-uniform) with a csrf hash,
- you use [content security headers](https://github.com/bnomei/kirby3-security-headers) with nouces,
- build and cache data for a logicless templating system like [handlebars](https://github.com/bnomei/kirby3-handlebars) or
- you want to cache data from an external source like an API.

Lapse was build to do exactly that: **Cache any data until set expiration time.**

Usage Examples
--------------

[](#usage-examples)

### Example 1: get/set

[](#example-1-getset)

```
$key = hash('xxh3', $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];
};
$data = lapse($key, $data);
```

### Example 2: with custom expiration time

[](#example-2-with-custom-expiration-time)

```
$key = hash('xxh3', $page->url()); // unique key
$expires = 5; // in minutes. default: 0 aka infinite
$data = function () {
    return [1, 2, 3];
};
$data = lapse($key, $data, $expires);
```

### Example 3: page object

[](#example-3-page-object)

```
$data = lapse(hash('xxh3', $page->url()), function () use ($kirby, $site, $page) {
    // create some data
    return [
        'author' => site()->author(),
        'title' => $page->title(),
        'text' => $page->text()->kirbytext(),
        'url' => $page->url(),
    ];
});
```

### Remove by Key

[](#remove-by-key)

```
$key = hash('xxh3', $page->url()); // unique key
$wasRemoved = \Bnomei\Lapse::rm($key);
```

Static Cache helper - lapseStatic()
-----------------------------------

[](#static-cache-helper---lapsestatic)

Sometimes you need to cache things only for the current request like when [reusing Kirbys Collections](https://forum.getkirby.com/t/remember-this-caching-in-kirby/23705/4#solution-with-a-static-cache-3). The `lapseStatic()`-helper makes things like that a bit easier. The closure to generate the data will only be called once, set its return value to a static cache and every recurring call to the collection will get the cached collection back from static memory array.

**site/plugins/example/index.php**

```
