Memcache 根据某种模式使条目无效?

发布于 2024-07-29 18:44:12 字数 177 浏览 5 评论 0原文

有没有办法根据通配符键使内存缓存中的条目无效?

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

data/1
data/2
data/3

有没有办法可以使用诸如 data/* 之类的内容使这些键失效? 一次性清除一堆陈旧数据将非常有帮助。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

王权女流氓 2024-08-05 18:44:12

最好的方法是在创建内存缓存密钥时提供版本控制密钥。 我们通过提供一个函数/方法来在我们的系统上创建密钥来实现这一点。

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

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

5:monkeyInfo:123:456

注意开头的“5”。 它来自一个硬编码的 keyNames 数组 => 版本。 因此,如果我们想要使系统中的每个“monkeyInfo”缓存值无效,我们只需将该数组中的数字更改为 6 即可。 从那时起,相同的调用将寻找

6:monkeyInfo:123:456

以下是密钥版本数组可能是什么样子的示例。 'makeKey()' 调用只是查看此数组以获取任何给定密钥的版本号。

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

您可以做各种各样的事情来使实现满足您的需求,但这就是它的基本要点。

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() uses the information in the cacheKeyVersions array and returns:

5:monkeyInfo:123:456

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

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.

云醉月微眠 2024-08-05 18:44:12

memcached 不支持命名空间删除。

官方 wiki 提供了有关如何解决此问题的建议:

memcached does not support namespaced deletes.

The official wiki has a suggestion on how to work around it:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文