Caching COUNT with PHP and Redis
forrst.com
Caching COUNT with PHP and Redis
1–10 of 13 posts
Re: Caching COUNT with PHP and Redis
#2Re: Caching COUNT with PHP and Redis
#3MySQL already caches these. You've added a cache on top of a cache. Is a round trip to the database so slow?
Re: Caching COUNT with PHP and Redis
#4Re: Caching COUNT with PHP and Redis
#5And perhaps MemcacheDB (http://memcachedb.org/) is a better bet if you don’t need Redis’s list and set operations. But I don’t understand why the cache needs to be persistent.
Re: Caching COUNT with PHP and Redis
#6Warning, this is a myth: once you starte relying on caching to serve your amount of traffic, flushing the cache will have the result of taking the site down. This is why persistence is an absolute requirement of a serious caching server IMHO. With Redis when things may be in desync it's better to selectively remove entries with (RANDOMKEY+DEL) at a rate that the system is able to handle.
Also given that you are using Redis that has atomic increments, why not going the extra mile and issuing INCR/DECR operations when something is added/removed?
Re: Caching COUNT with PHP and Redis
#7> if for some reason the memory cache diverges from the true count, we just wipe out the memory cache and the app takes care of regenerating it automatically Warning, this is a myth: once you starte relying on caching to serve your amount of traffic, flushing the cache will have the result of taking the site down. This is why persistence is an absolute requirement of a serious caching server IMHO. With Redis when thi…
Useful tip about randomkey and del, thank you.
I def. could switch it over to an incr/decr setup. Maybe I'll do that tonight.
Re: Caching COUNT with PHP and Redis
#8MySQL already caches these. You've added a cache on top of a cache. Is a round trip to the database so slow?
Re: Caching COUNT with PHP and Redis
#9MySQL already caches these. You've added a cache on top of a cache. Is a round trip to the database so slow?
Re: Caching COUNT with PHP and Redis
#10MySQL already caches these. You've added a cache on top of a cache. Is a round trip to the database so slow?
I was under the perhaps false impression that count star queries with or without where conditions are not cached on innodb tables.
On innodb, because of transactions, this is not possible, and it needs to actually count the rows.
BUT, the query itself is still cached - at least until the underlying table gets updated, which invalidates the cache (I'm not sure of the exact invalidation strategy, but it's part of MySQL and doesn't depend on the engine).