What is Cache / How Cache Works
Expand | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
We're talking about the HTTP Response Cache - there are others We mean "rendered Magnolia output" when we talk about what is being cached. Magnolia's default cache is based on Ehcache.
magnolia.cache.startdir=${magnolia.home}/cache <-- obviously, you may override this to put the cache someplace else ... you can override it in magnolia.properties, or in configuration: /modules/cache/config/cacheFactory/delegateFactories/cacheFactory@diskStorePath <-- make it an absolute path ... if you make it a relative path, it is treated as relative to magnolia.cache.startdir=${magnolia.home}/cache. <-- if we want to use a remote service (we'll see how to do this later), we need to use a diff tool.
|
Cache Flush Policy
Expand | ||
---|---|---|
When to flush
Executors Once a cache decision has been made, actions are taken by executors:
Executors also configure expiry headers.
|
Compression
Expand | ||||||
---|---|---|---|---|---|---|
| ||||||
Note where the gzip filter lives in the filter chain. We compress items we send out from cache. Typically, we compress text (because they are very easy to compress) objects like HTML, JS, CSS (OOTB) to 20% size before sending to browsers. We achieve further gains by streaming these sends directly from the JCR repo, rather than first storing them in memory. Generally, it is enough to compress text. We don't need to cache binary content (think about why not!), and Magnolia will not cache big objects (> 500k) anyway (see "in-memory threshold"). In-Memory Threshold Should we cache something, based on size? Testing shows that 98% of resources are served as fast from memory as from repository if those resources are > 500k in size. So in addition to maybe not caching binary content because it hopefully doesn't change often, if it is over this threshold, it comes from memory just as fast as from repository, because it takes time to stream so much data from repository. You can set a different value for this threshold programmatically. Testing Compression We can use tools like Web Sniffer to change the We could also just use
|
Caching Strategies
Expand | ||
---|---|---|
We don't want to cache everything: even if data from an observed Magnolia workspace does not change, some external data we pull in to use in some components on the page may have changed. This means ultimately that we have a different computed page to stream to the requester. Since we don't want to stream that response with old data, we take it out of the cache. Likewise, when we are developing JS or CSS or HTML on the Author instance, we don't want to cache that.
|
Cache Header Negotiation
Expand | ||
---|---|---|
This is a mechanism to allow templates (components) to influence if content should be cached, and for how long. If you don't want a page to be cached, but it's too late in the rendering process for something to be analyzed for caching. Examples:
can set them in code, or in templates, like so:
|
Other
Expand |
---|
The strictest (most precise) caching policy wins. Think about the case where we are caching multiple things on the same page ... let's say we have two components, one is static and one is dynamic. The dynamic one says "don't cache me", the static one says "cache me". Will this page be cached? No! Why not - because one component doesn't want to be cached. |
Cache Tools App
Cache Browser SubApp - used to log in from author to all publics ... can see what is in cache ... maybe can be used to help troubleshoot some common problems:
...