K
K
kamenevn2015-12-25 01:46:09
Redis
kamenevn, 2015-12-25 01:46:09

How to do caching?

Hello.
There is now:
Now there is an online store written in kohana. MySQL is used as a database. Memcached is used for caching.
One of the most visited pages is the home page. Products are displayed on the main page, each product is not a single select to the database, but rather a complex query with joins, etc. (cities, categories, number of purchases and other information). Caching is implemented as follows: The cache is checked in memcached and if there is no cache, then the data is taken from the database, the logic is processed, written to memcached (ready html) and given to the user. The caching time is 40 minutes, but once every 5 minutes the cache of the main page is deleted by the cron.
Purchase data changes approximately once every 10 seconds, so you need to update the cached data on the main page.
Question: How to organize caching more correctly? (provided that there can be different selections, pagination, etc.)
Now I want to do:
1. Make a cache for each specific product separately
2. Make a "trigger" system for deleting the cache, i.e. the product was updated, its cache was deleted
3. Is there a limit in memcached on the number of keys and their sizes?
4. Where can I read how caching is arranged in large / not very large companies, what is cached and how?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Litvinenko, 2015-12-25
@edli007

And now rotten eggs have been poured into me, because everyone loves to cook, no one likes to delve into someone else's opinion.
Personally, I think doing php caching is like carrying reinforced concrete blocks in your hands, because it's cheaper than hiring a crane.
As for SQL queries, you can optimize using the database itself, for example, create a function or cache queries by the database itself.

A
Alex Safonov, 2015-12-25
@elevenelven

We introduce a cache layer and an interface for working with it. This is important because it makes it easy to switch between different implementations.
The cache storage system must be shared across all PHP processes. (Keyspace)
A particular implementation can be chosen, changed, tried another. Start with Memcache, you can easily try Redis if you need something more complex key-value.
We add the finished html to the cache. Because generating html is quite a costly process.
Magento generally takes a radical approach to this - it caches everything and loads user-dependent blocks (basket) with Ajax.
Your cache layer will allow you to invalidate data by events. Expiration-time, on-update, on-sale, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question