开发者

Grouping/tagging cached values for invalidation / recalculation

开发者 https://www.devze.com 2023-02-19 11:54 出处:网络
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 combin

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 :)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号