perturbatio/wildcache

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

This package is auto-updated.

Last update: 2024-08-29 05:31:17 UTC


README

CircleCI Latest Stable Version Latest Unstable Version License Total Downloads

通过通配符查找或删除 Laravel 缓存中的项的能力。

使用方法

使用 WildCache,您可以使用 点符号 语法存储项,然后检索匹配的项以获取或删除所有匹配模式的项。

方法

Put - 写入缓存值

/** @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

get 方法始终返回任何匹配模式的项的集合,或者传入的默认值(默认为 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');