PHPackages                             bnomei/kirby3-php-cachedriver - 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-php-cachedriver

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

bnomei/kirby3-php-cachedriver
=============================

PHP based Cache-Driver

2.0.0(3y ago)112.6kMITPHPPHP &gt;=8.0

Since Nov 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bnomei/kirby3-php-cachedriver)[ Packagist](https://packagist.org/packages/bnomei/kirby3-php-cachedriver)[ Fund](https://buymeacoff.ee/bnomei)[ Fund](https://paypal.me/bnomei)[ RSS](/packages/bnomei-kirby3-php-cachedriver/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (18)Used By (0)

🐘 Kirby PHP Cache-Driver
========================

[](#-kirby-php-cache-driver)

[![Release](https://camo.githubusercontent.com/bb493400c68c285e134100bbcf61008111831c2011ade4f3161b6fb7b94bf359/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f762f626e6f6d65692f6b69726279332d7068702d63616368656472697665723f636f6c6f723d6165383166662669636f6e3d676974687562266c6162656c)](https://camo.githubusercontent.com/bb493400c68c285e134100bbcf61008111831c2011ade4f3161b6fb7b94bf359/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f762f626e6f6d65692f6b69726279332d7068702d63616368656472697665723f636f6c6f723d6165383166662669636f6e3d676974687562266c6162656c)[![Discord](https://camo.githubusercontent.com/36eaef1b06f4996feb7587aa3281dcbd658e57535bc6b5e10110ed108e7a7a03/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f646973636f72642f626e6f6d65693f636f6c6f723d3732383964612669636f6e3d646973636f7264266c6162656c)](https://discordapp.com/users/bnomei)[![Buymecoffee](https://camo.githubusercontent.com/62e55d1129b82bf9c2fd4656451e81ab87a9787e7c9676ca58276532ed9666ee/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f69636f6e2f646f6e6174653f69636f6e3d6275796d6561636f6666656526636f6c6f723d464638313346266c6162656c)](https://www.buymeacoffee.com/bnomei)

Elephant - a highly performant PHP Cache Driver for Kirby

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

[](#installation)

- unzip [master.zip](https://github.com/bnomei/kirby3-php-cachedriver/archive/master.zip) as folder `site/plugins/kirby3-php-cachedriver` or
- `git submodule add https://github.com/bnomei/kirby3-php-cachedriver.git site/plugins/kirby3-php-cachedriver` or
- `composer require bnomei/kirby3-php-cachedriver`

Usage
-----

[](#usage)

### Cache methods

[](#cache-methods)

```
$cache = \Bnomei\PHPCache::singleton(); // or
$cache = elephant();

$cache->set('key', 'value', $expireInMinutes);
$value = elephant()->get('key', $default);

elephant()->remove('key');
elephant()->flush();
```

### Cache file(s)

[](#cache-files)

All data is written at the end of the PHP script life-cycle. This does not count against your script execution time, but for example, when you change the value in the cache with each request, writing that big file every time time might prove inefficient. Furthermore, more incremental updates will be written during script execution depending on the `mono_dump` setting. Additions to the cache will also be written in temporary files to improve the stability of the cache.

### Serialization of data

[](#serialization-of-data)

This plugin defaults to a simple serialization logic, which is quick but only serializes primitive data types, closures, and objects that have a `toArray()`-method like `Kirby\Cms\Field` and `Kirby\Toolkit\Obj`. This should be enough for most use-cases. If you need broader support set `bnomei.php-cachedriver.serialize` to `json` which will en- and decode your data as JSON before storing it. That is a bit slower but will ensure your data contains only primitive types without the hassle of serializing it manually before caching it.

### OPCache

[](#opcache)

Make sure [OPCache is configured](https://www.php.net/manual/en/opcache.configuration.php) to load the PHP files from the cache without any delay. Most probably you will have to set these values in your `user.ini` or something similar! If you do not set these values, you might have outdated data being loaded from php files cached by OPCache instead of loading the right ones you want from disk.

```
opcache.enable=1
opcache.enable_cli=0 # default is 0, leave it like that
opcache.validate_timestamps=1
opcache.revalidate_freq=0 # default is 2, 0 => on every request
```

> Thanks, Al, for helping me get these config values right.

### Benchmark

[](#benchmark)

```
elephant()->benchmark(1000);
```

```
php : 0.03383207321167
file : 2.3811981678009
```

> ATTENTION: This will create and remove a lot of cache files and php-cache files

### No cache when debugging

[](#no-cache-when-debugging)

When Kirbys global debug config is set to `true` the complete plugin cache will be flushed and no caches will be read. But entries will be created.

### How to use Elephant with Lapse or Boost

[](#how-to-use-elephant-with-lapse-or-boost)

You need to set the cache driver for the [lapse plugin](https://github.com/bnomei/kirby3-lapse) to `php`. Please be aware that the *mono*-mode is not suited for concurrent writes.

**site/config/config.php**

```
