Improve the front end caching mechanism #11336
Replies: 2 comments
-
There is some overlap between this issue and #11377 -- linking them together. |
Beta Was this translation helpful? Give feedback.
-
@jonasraoni, I'd be interested in exploring ways to support a variety of front-end caching tools. The old Hopefully we can rely on Laravel for significant parts of this, e.g. cache the implementation and perhaps even some of the last-modified stuff, but we'll be a little hobbled in that by our partial adoption of both Eloquent and our non-Laravel handling of page requests. Charting a path towards standard adoption of Laravel would be a good thing here, and would hopefully keep us from growing out more custom code (and tech debt), which I'd really like to avoid. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
Our applications generate mostly static content, and the frontend lacks a good caching mechanism.
A nice cache strategy will highly improve the performance. The drawbacks are minimal, because once articles are published, it's unlikely the output will be changed often, it's not as sensitive as a product stock.
Current status
We have two settings,
[cache].web_cache
and[cache].web_cache_hours
, which enable a global cache for a couple of static pages, it works, but it has problems and can be improved.A plugin was created with some of the ideas presented below: https://github.com/jonasraoni/frontEndCache.
Ideas
First step
max-age
(the browser will be lazier to look for updates)gzip
, therefore the content can be served packed right away (if unsupported by the client, unpacking instead of storing N different formats is an option).etag
(hash check) andcache-control
(specify when a new request/cache validation should be done) are enough.isBot()
check), this will also allow playing with highermax-age
values for thecache-control
.sitemap
).Second step
Ideally we should probably implement a granular cache strategy at a template level. This will allow us to cache content even for logged in users. The content should be better fragmented, and each include should have its cache controlled individually (e.g. if the template has user data, the cache can be done, but it cannot be shared).
As templates can have hooks, plugin developers should be able to integrate with the cache invalidation (e.g. change the expiration, content hash, implement a callback, ...).
Third step
The cache invalidation can be improved. Instead of invalidating by time, we can listen to events, check modification dates of records, make use of hashes, etc.
Preemptive cache, where we generate cached content after saving a record, is also an option, it would probably require defining a dependency chain.
Fourth step
Back end caching can be done as well.
Beta Was this translation helpful? Give feedback.
All reactions