How to use the FileCache object? Is there a better way to get a cache object?

Hi, how can I use the FileCache object in kirby3: https://getkirby.com/docs/reference/@/cache/filecache/__construct

A look into the source code told my that this is based on a kirby3 Toolkit version so I used the right namespace:

$cache = new Kirby\Cache\FileCache([
      'root' => $kirby->roots()->cache(),
      'extension' => 'ser',
]);

Is there a better way to get a cache object?

Okay I figured out that I can add a new element to the config file like this:

'cache.vendors' => [
    'extension' => 'json',
],

So I can get the cache object with:

$cache_vendors = $kirby->cache('vendors');

To use a method like ->expired I have to add the key:

$cache_vendors->exists('xyz') but this is not working…

So I have to check with ->get()

See our guide on caching. The reference is more suitable if you already have the code working and need more information on specific implementation details. :slight_smile:

We have refactored the cache implementation for 3.2.0 so that $cache->exists() will finally work again.

Sounds great if you will fix this in 3.2.0

If you want, you can already test the new implementation in this branch.

You should be able to download a ZIP or install it in any other way you normally do. But please don’t use it in production yet. :slight_smile:

Thanks…