perturbatio/wildcache

v2.0.4 2022-08-29 13:45 UTC

This package is auto-updated.

Last update: 2024-10-29 05:47:49 UTC


README

CircleCI Latest Stable Version Latest Unstable Version License Total Downloads

Adds the ability to find or remove items in the Laravel cache by wildcard.

Usage

Using WildCache, you can store items using a dot.notation syntax, then retrieve the item matching to get or remove all items matching a pattern.

Methods

Put - Write a value to cache

/** @var \Perturbatio\WildCache\WildCache $wildCache */
$wildCache = app('wildcache');
// use the WildCache to store the item with a dot separated key
$wildCache->put('test.WildCache.itemA', 9999, now()->addMinutes(10));
$wildCache->put('test.WildCache.itemB', 8888, now()->addMinutes(10));

Get

The get method always returns a collection of any items that match the pattern, or the default value passed in (defaults to null)

/** @var \Perturbatio\WildCache\WildCache $wildCache */
$wildCache = app('wildcache');
// returns the first item that has a key prefixed with `test.WildCache.`
echo $wildCache->get('test.WildCache.*')->first(); 
/** @var \Perturbatio\WildCache\WildCache $wildCache */
$wildCache = app('wildcache');
echo $wildCache->get('some.key', 'default_value')->first();
/** @var \Perturbatio\WildCache\WildCache $wildCache */
$wildCache = app('wildcache');

// use the WildCache to store the item with a dot separated key
$wildCache->put('test.WildCache.itemA', 9999, now()->addMinutes(10));
$wildCache->put('test.WildCache.itemB', 8888, now()->addMinutes(10));

// retrieve the first that matches the key
echo $wildCache->get('test.WildCache.*')->first(); // 9999
echo $wildCache->get('test.WildCache.*')->get('wildcache.test.itemB');