Memcache是​​否根据模式使条目无效? [英] Memcache invalidate entries according to a pattern?

查看:102
本文介绍了Memcache是​​否根据模式使条目无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以根据通配符使memcache中的条目无效?

Is there a way to invalidate entries in memcache according to a wildcard key?

因此,如果我具有以下内存缓存键:

So if I have the following memcache keys:

data/1
data/2
data/3

有没有办法让我像data/*这样的键无效?一口气清除一堆过时的数据将非常有帮助.

Is there a way I can invalidate those keys with something like data/*? It would be extremely helpful to clear out a bunch of stale data in one swoop.

推荐答案

最好的方法是在创建内存缓存密钥时提供版本控制密钥.为此,我们提供了一个用于在系统上创建密钥的功能/方法.

The best way is to provide a versioning key when creating your memcache key. We do this by providing a single function/method for creating a key on our system.

$var1 = 123;
$var2 = 456;
$cacheKey = makeKey('monkeyInfo', $var1, $var2, ...);

makeKey()使用cacheKeyVersions数组中的信息并返回:

makeKey() uses the information in the cacheKeyVersions array and returns:

5:monkeyInfo:123:456

请注意开头为"5".这来自keyNames =>版本的硬编码数组.因此,如果我们要使系统中的每个"monkeyInfo"缓存值均无效,我们只需要将该数字更改为数组中的6.从那时起,同一通话将一直在寻找

Notice the '5' at the beginning. That comes from a hard-coded array of keyNames => versions. So if we want to invalidate EVERY 'monkeyInfo' cache value in the system we simply have to change that number to 6 in the array. From then on the same call will be looking for

6:monkeyInfo:123:456

这是密钥版本数组的外观示例.调用makeKey()只是简单地查看此数组以获取任何给定密钥的版本号.

Here is an example of what the key version array might look like. The 'makeKey()' call simply looks into this array to get the version number for any given key.

$cacheKeyVersions = array(
    'monkeyInfo'   => 5,
    'zebraInfo'    => 2
);

您可以做各种事情来使实现符合您的需求,但这是它的基本要旨.

You could do all sorts of things to make the implementation match your needs, but that's the basic gist of it.

这篇关于Memcache是​​否根据模式使条目无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆