Open ripperdoc opened 10 years ago
New take on caching strategy: Set a flag on g object whether the request is cache-control: public or private. Make it public by default, but any function that in template will result in a variation based on the user, can be publicly cached. So any such function should set the flag to private.
Note that there are other variations that may create stale content in cache, such as outputting HTML that depends on current time (typical example: relative dates).
As the root header includes user data, currently virtually all templates would be private cached. But if we remove that part, and fetch it with jquery, it would make lots of them publicly cached.
What should make a template private cached:
Wait, a problem: if we publicly cached the the unprivileged version, won’t the privileged ones also get that, as their request never continues to the Flask server? We can use Vary header for this, but if we put Vary on the cookie/user, it would almost never cache publicly
We can add headers to the Nginx cache key, to ensure we cache different versions. We need to make sure a privileged and unprivileged page gets different cache keys. We could:
We need to cache to do a public website, rather than generating template on the fly. But some parts of the current templates, e.g. the header with user name, will be unique for every user and therefore add very little caching value. We need to find a way to cache most of the page (e.g. mainly the articles).
Some more details:
Overall, we shouldn't rush to cache anything until we have researched performance. Such as:
Consider these articles before starting: https://amphtml.wordpress.com/2015/12/16/why-amp-is-fast/ http://flask.pocoo.org/docs/0.10/patterns/caching/ http://brunorocha.org/python/flask/using-flask-cache.html https://pythonhosted.org/Flask-Cache/ https://serversforhackers.com/nginx-caching/
Also, this is fundamental for the total performance: https://developers.google.com/web/fundamentals/performance/