The Flat File CMS Statamic allows the caching of pages through its 'Static Cache' feature, enabling very fast loading speeds.
However, the use of complex plugins or extensions, such as Markdown Highlight or spatie/commonmark-shiki-highlighter, can significantly extend the caching duration for individual pages. For extensive websites, the complete renewal of the cache can take several minutes and heavily load the server during deployments.
Two approaches are available for optimization. In the default mode, 25 pages are processed simultaneously, which can increase server load. This number can be reduced (for example, to just one page, thus eliminating parallel processing). This setting can be changed in the file config/statamic/static_caching.php by adding the
warm_concurrency parameter to the desired caching strategy:
'strategies' => [ 'half' => [ 'driver' => 'application', 'expiry' => null, 'warm_concurrency' => 1, // Add this parameter ], ]
As a result, fewer pages are cached simultaneously, significantly reducing server load. However, this will considerably lengthen the warmup phase of the cache.
For more efficient deployment design, the cache warmup can be shifted to the queue. In this way, the cache is warmed up in the background, and the deployment can be completed without a completed warmup. It is important here that the queue is configured in a mode other than
sync (otherwise the queue will not be processed in the background). To move the cache warmup to the queue, the
--queue parameter must be used in the deployment script:
php artisan statamic:static:clear php artisan statamic:static:warm --queue
With this method, deployments are quickly completed, the web server is noticeably relieved after a deployment, and the cache is warmed up in the background.