Caching

Caching is the life-blood, the secret-sauce, and the wizard behind the curtain of Statamic. There are several caching layers, each with its own purpose. Let's explore each one and its specific purpose.

The Stache

Purpose: Replace the traditional database

Instead of using a relational database like MySQL as a storage system, Statamic aggregates the data in your content files into an efficient, index-based system and stores it in Laravel's application cache. We call this the "stache", and we like to make mustache jokes about it.

Tom Selleck as Magnum P.I.
Behold, the stache of all staches!

The stache is ephemeral and can be blown away and rebuilt from scratch at any time without losing data. This is most often done when content or settings change, or when updates are deployed to a production server.

The CLI has commands to clear, warm, and refresh (clear and then immediately warm) the stache.

php please stache:clear
php please stache:warm
php please stache:refresh

There are settings you can configure to improve the performance of the stache, just like with a relational database. Learn more about the Stache and it's various settings.

Hot Tip!

You cannot disable the stache — it is critical architecture.

Application Cache

Purpose: Make site faster

The application cache is used by your site/application, third-party addons, Laravel Packages, and Statamic itself to store queries, data, and the results of resource intensive operations for pre-defined lengths of time. It uses Laravel’s Cache API.

For example, the Image Transform feature uses this cache to store all the manipulated images at their various sizes and transformations. When the arguments that generate those manipulations change, the cached images are blown away and new ones are generated and cached.

Each item inserted into the cache can optionally and automatically expire after a specified length of time.

If you want to clear the entire application cache at once, use the artisan cache:clear command.

php artisan cache:clear
Hot Tip!

The Stache is stored inside the application cache, so if you clear it, you don't need to also clear the Stache.

View Fragments

Purpose: Make a view faster

There are times when you may want to simply cache a section of an Antlers template to reduce load times for a particularly "expensive" bit of logic or content fetching. This is where the cache tag comes in.

Wrap your markup in {{ cache }} tags, specify a duration, and your site is zippy and, one might say, quite delicious once again.

{{ cache for="1 hour" }}
something impressive but slow here
{{ /cache }}
<s:cache for="1 hour">
something impressive but slow here
</s:cache>

Static Caching

Purpose: Ultimate speed at the cost of dynamic features

There is nothing faster on the web than static pages, except static pages without JavaScript and giant hero images, of course. Statamic can cache static pages and pass routing off to Apache or Nginx through reverse proxying.

Static Caching can be enabled on a per-page level, allowing you to mix and match dynamic features when needed.

Hot Tip!

This should not be confused with Static Site Generation, which is the fastest possible way to run your site, involving generating actual .html files used to serve your site, skipping PHP and the Statamic application entirely.

Learn more about Static Caching to make your sites start flying! We're talking 2ms response times here.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →