Laravel 5.2でRedisキャッシュを使用しており、年とソースの2つのタグ(基本的に)が付いたキーを持っています。
例:
$this->cache->tags(['online', 2016])->put("key1", $value1, 10));
$this->cache->tags(['online', 2016])->put("key2", $value2, 10));
$this->cache->tags(['online', 2017])->put("key3", $value3, 10));
$this->cache->tags(['online', 2017])->put("key4", $value4, 10));
$this->cache->tags(['database', 2016])->put("key5", $value5, 10));
$this->cache->tags(['database', 2016])->put("key6", $value6, 10));
$this->cache->tags(['database', 2017])->put("key7", $value7, 10));
$this->cache->tags(['database', 2017])->put("key8", $value8, 10));
2016年とオンラインのタグのキャッシュをフラッシュしたい。
これを使用する$this->cache->tags(['online', 2016])->flush();
ことがですべてをフラッシュしますどのすなわち、タグの、いずれかonline
または 2016
(この場合はKEY1、KEY2、KEY3、KEY4、KEY5、KEY6)。
私は含めて削除すべてにしたいすべてのタグ、すなわち、両方 online
と2016
(この場合の唯一KEY1とKEY2)
したがって、これには少し掘り下げが必要でしたが、ここに評決があります。
はい、これは技術的に可能です(可能な限り最高の種類ですか?)
まず、RedisTaggedCache
(redisでのタグ付けの実装を担当する)は、すべてのタグメンバーキーをredisセットに格納します。それがどこにあるかを発見する方法と、すべてのキーを取得する方法は次のとおりです。
function getAllTagKeys($cache,$tags) {
$tagStore = new TagSet($cache->getStore(),$tags);
$key = "<prefix>:{$tagStore->getNamespace()}:". RedisTaggedCache::REFERENCE_KEY_STANDARD;//use REFERENCE_KEY_FOREVER if the keys are cached forever or both one after the other to get all of them
return collect($cache->getRedis()->smembers($key));
}
次に、次のことができます。
getAllTagKeys($this->cache, ["online"])
->insersect(getAllTagKeys($this->cache, ["2016"]))
->each(function ($v) {
$this->cache->getRedis()->del();
});
これはこれを行うための恐ろしい方法のように見えます。おそらく、Laravelに機能リクエストを送信する方が賢明です。これは、公開すべきもののように見えるからです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加