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.
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.
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.
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.
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.
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.
You should be aware of some limitations and caveats of using the stache. For instance:
.yaml or .md extensions.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.
Written by
Writing and maintaining @LaravelMagazine. Host of "The Laravel Magazine Podcast". Pronouns: vi/vim.
Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.