December 4th, 2023

Understanding Statamic Stache

Understanding Statamic Stache

Statamic stache is a powerful feature that allows you to store your content in a fast and efficient way. In this blog post, I will explain what the stache is, how it works, and how you can use it to improve your site performance and development experience.

What is the stache?

The stache is a term that Statamic uses to describe its content cache system. The stache is not a typical cache that stores the rendered HTML output of your pages, but rather a cache that stores the raw data of your content, such as entries, terms, assets, users, etc.

The stache is composed of two parts: the file stache and the cache stache. The file stache is a set of JSON files that mirror the structure and content of your content files (such as YAML or Markdown). The cache stache is a key-value store (such as Redis or APC) that holds the parsed and processed data of your content.

Why use the stache?

The main benefit of using the stache is that it reduces the number of file reads and parses that Statamic has to do when rendering your site. This means that your site will load faster and consume less server resources.

How to use the stache?

The stache is enabled by default in Statamic, so you don't have to do anything to start using it. However, there are some things you should know and do to make the most out of it.

First

You should configure your cache driver in your .env file. Statamic supports several cache drivers, such as file, database, Redis, Memcached, etc. The default driver is file, which means that Statamic will store the cache stache in JSON files inside the storage/framework/cache directory. However, this driver is not recommended for production environments, as it can be slow and unreliable. You should use a more robust driver, such as Redis or Memcached, for better performance and scalability.

Second

You should clear your stache whenever you make changes to your content files outside of Statamic's control panel. For example, if you edit or add a YAML or Markdown file directly on your server or through Git. This is because Statamic does not monitor these changes and will not update the stache accordingly. To clear your stache, you can run the php please stache:clear command or use the "Clear Stache" button in the control panel.

Third

You should be aware of some limitations and caveats of using the stache. For instance:

  • The stache does not support dynamic content, such as PHP code or Antlers tags, inside your content files. You should use partials or modifiers for this purpose.
  • The stache does not support custom file extensions for your content files. You should use YAML or Markdown files with .yaml or .md extensions.
  • The stache does not support multiple sites with different locales sharing the same content files. You should use separate directories for each site/locale.

Conclusion

Statamic stache is a great feature that can boost your site performance and development experience. It allows you to store your content in a fast and efficient way and enables some advanced features that are not possible with file-based content alone. However, you should also be aware of some configuration and usage tips to make the most out of it. I hope this blog post has helped you understand what the stache is, how it works, and how you can use it.

Statamic Ninja

Comments

Marian Pop

PHP / Laravel Developer. Writing and maintaining @LaravelMagazine. Host of "The Laravel Magazine Podcast". Pronouns: vi/vim.

Subscribe to our newsletter

Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.

Weekly articles
We send a new issue of the newsletter every week on Friday.
No spam
We'll never share your email address and you can opt out at any time.