I’ve got a large ECommerce website running LAMP and was wondering how best to easily implement Memcached?
-
Store all queries in memcached for a certain period – sounds pointless
-
Store only certain important data like product information into Memcached and make sure the proper updates can expire it correctly – sounds like an end to end solution.
-
Store complex query results which do not change often – involves a lot of static code
Trying to get an overview of what changes I should make to take the best advantage of memcached.
Thanks 🙂
I’d let your users decide.
In other words rather than trying to second guess what will work best, I’d rework ALL the database queries to use memcached along the lines of;
so – return the results from cache.
database and write back to memcached
so the next time it’s in the cache.
deletes invalidate the appropriate
cache keys.
Now given that 3) might be complex, I’d use that factor to choose which queries to load through the cache – if it’s hard and/or time consuming to invalidate the cache, don’t cache back those queries to start with.
Because memcached will automatically dump the least recently used keys when the store approaches capacity, you can set everything to never expire and just allow available resources to determine what is currently in the cache. This will largely be determined by user behaviour (which products are popular etc) and hence my first comment about letting the users decide.
It’s also worth saying that you should ensure your MySQL database is well tuned first as that can often be an easier win. Query caching, checking heavy queries with Explain to tune your indexes etc, all of this can have a greater impact.