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

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

bnomei/kirby3-apcu-cachedriver
==============================

APCu based Cache-Driver with garbage collection and in-memory store

1.0.1(3y ago)113MITPHPPHP &gt;=8.0

Since Jul 27Pushed 1y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Kirby Extended APCu Cache-Driver
================================

[](#kirby-extended-apcu-cache-driver)

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

Extends the basic APCu Cache-Driver for Kirby with garbage collection and in-memory store

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

[](#installation)

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

Why
---

[](#why)

### Memcached &lt; File &lt; Redis &lt; SQLite &lt; APCu

[](#memcached--file--redis--sqlite--apcu)

Kirby ships with built-in support for File, Memcached, and APCu Cache Drivers. APCu is widely available and performs great. Its only drawback is the limited memory size compared to SQLite or Redis.

### In-memory store

[](#in-memory-store)

Usually, each call to the same cached item even repeated calls in the same HTTP request, would yield repeated requests to the APCu cache. With this plugin's in-memory store, retrieved items will be stored in a PHP array for the current http request and returned from there without the round trip to APCu. This might increase the total memory usage of your PHP script but significantly speeds up repeated calls. You can turn of this behaviour in the settings if you do not need it.

### Garbage Collection

[](#garbage-collection)

Kirby removes expired cached items only if they are requested again and then deemed expired or when the cache is flushed completely. This might result in long-expired items taking up memory in the cache.

The default APCu implementation does not actively collect garbage but only removes expired cache items when running out of memory. That is a perfectly fine strategy. This plugin minimizes this behaviour by actively purging expired items.

Usage
-----

[](#usage)

### Cache methods

[](#cache-methods)

```
$cache = \Bnomei\ApcuCache::singleton(); // or
$cache = apcugc();

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

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

### Benchmark

[](#benchmark)

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

```
apcugc : 0.026898145675659
file   : 0.13169479370117
```

> ATTENTION: This will create and remove a lot of cache files and apcu entries

### No cache when debugging

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

When Kirby's global debug config is set to `true,` the complete plugin cache will be flushed, and no caches will be read. However, entries will be created. This will make your life easier—trust me.

### How to use ApcuGC with Lapse or Boost

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

You must set the cache driver for the [lapse plugin](https://github.com/bnomei/kirby3-lapse) to `apcugc`.

**site/config/config.php**

```
