对缓存值进行分组/标记以使其失效/重新计算

发布于 2024-10-25 19:28:14 字数 983 浏览 1 评论 0原文

范围:基于 PHP-mysql 的站点,使用 memcached。
缓存问题主要与价格有关。由于价格计算与因素组合(包括产品的特定组合)直接相关,因此有很多可能的价格。

当价格计算所需的数字之一更新时,许多缓存的项目应该失效。并非所有组合都在缓存中,将它们全部放入其中是不可行的,或者至少是不需要的。

我想要的是使与该单一产品有关的所有价格无效(或更新)。因为它们是组合,所以当然,使具有特定名称(例如 $productId_price)的键失效并不是一个简单的事实(参见示例)。

我的理想情况是能够用对该条目有影响的所有产品来标记缓存条目,这样我就可以“找到”它们。

总结/举例:
我有 15 种产品#。这些产品目前在我的缓存中:

 1) "price_product1_product2"            => 200
 2) "price_product1_product3"            => 300
 3) "price_product5_product12"           => 250
 4) "price_product4_product1_product12"  => 203

现在产品 1 对我们来说变得更加昂贵,因此基于该产品的所有价格都需要重新计算。我不想遍历涉及 product1 的所有可能的组合,因为这会包含太多的键,其中大多数甚至不应该在缓存中。

我想到的一个解决方案是将缓存条目 1、2 和 4 标记为“product1”(当然还有其他产品),这样我就可以轻松找到它们,但 memcached 不支持该解决方案。我可以通过将所有使用过的密钥保存在数据库中来模拟这种行为,但我担心这只会减慢速度,而速度是缓存的原因之一。

对此有什么解决方案吗?
还有其他缓存系统可以做到这一点吗?
有没有办法在当前设置下快速完成此操作?
尖端?

# 当然我还有更多产品:)

Scope: PHP-mysql based site, using memcached.
Caching issue is mostly about prices. Because of a price-calculation that is directly linked to what combination of factors, including the specific combination of products, there are a LOT of possible prices possible.

When one of the numbers needed for the price-calculation is updated, a lot of cached items should be invalidated. Not all combinations are in the cache, and putting all of them in there is not feasible or at least not wanted.

What I want is to invalidate (or update) all prices that have something to do with that single product. Because they are combinations, it is not a simple fact of invalidating keys with a certain name like $productId_price ofcourse (see example).

My ideal situation would be to be able to tag cache-entries with all products that are of influence to that entry, so I can 'find' them all.

To summarize/as example:
I have 15 products#. Of these products there are in my cache currently:

 1) "price_product1_product2"            => 200
 2) "price_product1_product3"            => 300
 3) "price_product5_product12"           => 250
 4) "price_product4_product1_product12"  => 203

Now product 1 became more expensive for us to buy, so all prices based on that product need a recalculation. I do not want to go over EVERY possible combination that involves product1, because that would include too many keys, most of them should't even be in the cache.

One sollution I thought up, but which isn't supported by memcached, is to tag cache entry 1, 2 and 4 as "product1" (and also with the other products ofcourse), so I could find them easily. I could emulate this behaviour by saving all used keys in a database, but i'm affraid that would only slow things down, and speed is one of the reasons for the cache.

What would be a solution for this?
Are there other cache-systems that can do this?
Is there a way to quickly do this with the current set-up?
tips?

# I have more products ofcourse :)

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

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

发布评论

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

评论(2

糖果控 2024-11-01 19:28:14

一位朋友向我推荐了这个选项 memcached-tag。这看起来像是对这个问题的真正接近的答案。不过,我们不会很快使用它,因为它已经很老了,而且似乎没有积极开发。

A friend pointed me towards this option memcached-tag. This looks like a real close answer to the question. We will not be using this very soon though, because it is quite old and doesn't seem to be in active development.

权谋诡计 2024-11-01 19:28:14

当前的共识(离线)似乎是没有这样的“默认”缓存系统可用。最接近的解决方案是使用某种形式的数据库(NoSQL、MongoDB)并自己编写代码。

The current consensus (offline) seems to be that there is no such 'default' cache system available. The closest sollution would be to use some form database (NoSQL, MongoDB) and code for it ourselves.

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