Get started with 33% off your first certification using code: 33OFFNEW

Warming the cache in Statamic

3 min read
Published on 20th May 2024

Statamic, a flat-file CMS built on Laravel, offers a unique approach to managing content and performance. Unlike traditional databases, Statamic uses the 'Stache', a sophisticated caching and indexing system, to store content data. Warming up the cache in Statamic can significantly improve site performance, especially after updates or during deployments. This article will guide you through using the stache:warm command and integrating it into your deployment process.

Understanding Statamic's Cache

Statamic's cache system, or the Stache, is essential for speeding up content delivery by storing processed data in a quickly accessible format. The Stache handles indexing all content types, from entries and terms to global variables, which means a warm Stache reduces the load times and enhances the overall user experience.

What Does Warming the Cache Mean?

Warming the cache involves pre-building and storing the cache for all possible queries that might be run during regular page requests. This is particularly useful after the site has been updated or when new content has been published. Warming the cache ensures that these updates are immediately reflected in the performance of the site without the first few visitors experiencing slower page loads.

The stache:warm Command

Statamic includes a specific Artisan command, stache:warm, which is designed to prebuild the cache. This command is particularly handy after deployments or during maintenance tasks when caches are cleared or become stale. The stache:warm command processes and caches all content, ensuring that your site continues to load quickly, even right after a significant update.

How to Use the stache:warm Command:

Open your terminal and navigate to your Statamic project directory. Run the following command:

php artisan stache:warm

This command triggers Statamic to pre-process and cache all entries, terms, and other content, effectively warming up the Stache.

Integrating stache:warm into the Deployment Process

To ensure optimal performance, it's advisable to integrate the stache:warm command into your deployment process. Here’s how to do it effectively:

  1. Clear Existing Cache: Start by clearing the existing cache to remove any stale or outdated cached content. You can do this using:

    php artisan cache:clear
    php artisan statamic:stache:clear
  2. Update Content and Codebase: Deploy updates to your content or application codebase as required. This may involve pulling changes from a version control system like Git.

  3. Warm the Stache: After deploying the updates and before the site goes live, run the stache:warm command. This ensures that all changes are reflected in the cache, and the cache is built using the latest content and structure.

  4. Automate the Process: To streamline operations and reduce manual intervention, automate this process within your deployment script. Most continuous integration and delivery (CI/CD) systems allow you to script these commands as part of the deployment pipeline.

When to Use stache:warm

  • As part of the deployment process, especially if you're updating content or any part of Statamic’s structure.
  • If you import or modify a significant amount of content.
  • Periodically as part of scheduled maintenance, even if there haven’t been substantial changes, to ensure the cache is fresh and efficient.

Efficient caching is crucial for the performance of any CMS. In Statamic, using the stache:warm command as part of your deployment process ensures your site remains fast and responsive, regardless of the scale of updates or traffic. By integrating cache warming into your routine, you not only enhance user experience but also leverage Statamic’s capabilities to the fullest. Remember, a well-maintained cache translates to a smoother and faster site, contributing significantly to overall site success.