Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Here you can enter a specific URL to be removed from HTTP cache. This can be handy for production environments when a single page has been changed but is still cached. Does not restart the application server.

Fragment caching

Another powerful caching component is the fragment cache. It lets you save and retrieve arbitrary strings, code or HTML fragments.

This is useful for caching parts of a dynamically generated HTML page that would otherwise be costly or time consuming to render. E.g. a deeply nested dynamic navigational element, or an element that consumes third-party remote data on the server side.

Info
iconfalse
titleCaution

Always set TTL for a fragment or it will reside in the cache permanently! (or until it is removed programmatically or manually)

Dynamic cache keys

Sometimes you might want to cache a fragment that is dependent on a CMS entity and have that fragment automatically change when the entity is updated.
This is possible by using the cacheKey method of the entity and use the resulting string as a cache key. This way, a different cache key will be requested in case the entity is changed.
You can also nest such fragments and use the cacheKey method on all dependent entities to build a compound key.

Code Block
languagejs
collapsetrue
// Suppose we have some products in the variable 'products'
var compoundKey = products.map(x => x.cacheKey).join();
function renderProducts() {
	var output = products.map(function(product) {
		return cache.getOrSet(product.cacheKey, function() { renderProduct(product) }, true, 3600);
	});
}
var compoundMarkup = cache.getOrSet(compoundKey, renderProducts, true, 3600)
function renderProduct(product) {
	//...
}


See also

JSMA cache - Using the fragment cache.
JSMA system - programmatically checking if the cache or developer cache is active.