sylweriusz/taggedcache

缓存(redis或memcache),快速删除,可选基于标签

v1.5.5 2023-05-29 23:14 UTC

This package is auto-updated.

Last update: 2024-08-30 01:14:36 UTC


README

非常简单的缓存,可选带有标签,以便快速删除某些键组。

使用composer安装

composer require sylweriusz/taggedcache

初始化

$cache = new \TaggedCache\Memcache('127.0.0.1'); //memcache server address
//or
$cache = new \TaggedCache\Redis('192.168.1.34'); //redis server address

###用法

$key  = md5("item name and unique params ".json_encode($params));
$tags = ['tag_for_delete'];

//try from cache, and save if not exists
if (!$result = $cache->load($key, $tags)){
    $result = json_encode($params); // anything time consuming what You want to do with $params
    $cache->save($result, $key, $tags, 1200); //remember this for 1200 sec
}

###缓存清理

//clean all items    
$cache->clean('all');

//if one of $params get changed do somethink like this
$cache->clean('matchingAnyTag',['tag_for_delete', 'or_another_tag']);