发生更新时使用 mysql 代理的 memcached 会过期吗?

发布于 2024-09-26 08:09:20 字数 119 浏览 0 评论 0原文

我正在运行 mysql 代理,它接受查询,对其执行 md5,并将结果缓存到 memcached 数据库中。当 Rails 应用程序中发生更新导致该缓存失效时,就会出现此问题。关于如何使缓存中所有正确的键当时失效有什么想法吗?

I have mysql Proxy running which takes a query, performs an md5 on it, and caches the result into a memcached DB. the problem occurs when an update happens in the rails app that would invalidate that cache. Any ideas on how to invalidate all of the proper keys in the cache at that time?

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

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

发布评论

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

评论(1

一曲琵琶半遮面シ 2024-10-03 08:09:20

问题的核心是你不知道密钥是什么,因为它是 md5 生成的。

但是,您可以通过不存储该查询的数据来缓解该问题。

您的查询可能看起来像这样“SELECT my_data.* FROM my_data WHERE条件”

但是,您可以通过使用此查询来减少数据的冗余

SELECT my_data.id FROM my_data WHERE条件

然后是

Memcache.mget( ids )

这不会禁止返回不再符合条件的数据,但可能会减少返回过时数据的情况。

--

另一种选择是研究使用命名空间:请参见此处:

http://code .google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing

您可以为所有主要查询命名。您将无法删除密钥,但可以更改密钥版本 ID,这实际上会使您的数据过期。

逻辑上很混乱,但你可以在一些错误的查询上使用它。

--

最后,您可以将这些查询存储在不同的内存缓存服务器中,并更频繁地刷新。

The core of the problem, is you don't know what the key is since it is md5 generated.

However, you can mitigate the problem by not storing data for that query.

You query may look like this "SELECT my_data.* FROM my_data WHERE conditions"

However, you can reduce the redudeancy of data by use this query instead

SELECT my_data.id FROM my_data WHERE conditions

Which is then followed up by

Memcache.mget( ids )

This won't prohibit the return on data that no longer matches the conditions, but may mitigate returning stale data.

--

Another option is to look into using namespaces: See here:

http://code.google.com/p/memcached/wiki/NewProgrammingTricks#Namespacing

You can namespace all of your major queries. You won't be able to delete the keys, but you can change the key version id, which will in effect expire your data.

Logistically messy, but you could use it on a few bad queries.

--

lastly, you could store those queries in a different memcache server and flush on a more frequent basis.

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