Fragment Cache

Last updated on June 26, 2024.

You can cache specific parts of a page or layout using fragment caching. An example of an everyday use-case scenario is to cache fragments that take a lot of time to fetch or render, for example, a long-running GraphQL query.

Testing the Cache

You can test the cache by adding a random string and refreshing the page:

  • The string remains the same when the page is rendered from the cache.
  • The string changes when the cache is invalidated (e.g. after the time specified (in seconds) in the expire property).

app/views/pages/fragment-cache-simple.liquid

Example

This example demonstrates rendering a lot of data. In this case the data is generated inline. In the real world, this would be fetched from the database:

app/views/pages/fragment-cache-long-running.liquid

Authentication and Cross-Site Request Forgery Tokens

If you cache a fragment that includes a token (like an generated for a form request), the token gets cached. This could, for example, prevent the user from submitting a form.

Insites automatically processes the cache and updates those tokens if you use the form Liquid tag. If you're using JavaScript to submit forms, you can obtain the CSRF token for the current page from a cookie named .

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.