L
L
last72014-01-11 00:04:48
Django
last7, 2014-01-11 00:04:48

What is the best way to organize caching in Django?

Actually, I know some completely "banal" things (caching in templates / requests), I looked at different batteries.
Actually, there is an online store with large catalogs of goods. You can cache the requests themselves, but problems arise when generating templates, that is, they take almost all the time - you can use the block cache, but the problem is that some directories are little visited (4 per day), it turns out that even setting the lifetime to 12 hours , every second visitor will face a long wait.
Ok, you can "score" on these 4 users, but let's say I need to indicate in the catalogs if the product is already in the basket or not. In this scenario, the cache is needed for each user - that is, in fact, you need to keep directories for each user, + again a delay during the update and the first call. The same situation with the blog, I need to indicate how many new comments have appeared in the post since the last visit (ala habr).
Actually, the question is how to cache large blocks while saving individual information in them for each of the users, whether it is "already in the basket" or "+40 new comments"? Where can I read in-depth material on how to organize caching on sites in general?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yeletsky, 2014-01-11
@Tiendil

It seems to me that it is not the rendering of templates that slows down, but something else.
>Actually, the question is how to cache large blocks while storing individual information in them for each of the users
Transfer the display of this information to the JavaScript side. The html block is cached without changing data, and in the browser JS sets them separately.
> it turns out that even setting the lifetime of 12 hours, every second visitor will face a long wait.
1. you can set the time to 120 hours :-)
2. you can generate the entire html to disk and distribute statics, updating only when the products are updated.
3. write a script that will periodically bypass the site and initiate caching.
At the same time, I recommend reading about versioning the cache.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question