定制 f_roepstorf/static-cache-buster 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

f_roepstorf/static-cache-buster

Composer 安装命令:

composer require f_roepstorf/static-cache-buster

包简介

Warm the Statamic static cache without causing cache misses for visitors

README 文档

README

This addon enhances Statamic's static caching by allowing you to safely rebuild and swap the static cache without serving stale content during the build process.

How It Works

The addon extends Statamic's FileCacher to recognize a special header (X-Statamic-Cache-Buster) that signals when a request is coming from the cache warming process. When this header is detected, the cacher will ignore any existing cached content and generate fresh content instead.

This ensures that visitors always get a cached response when rebuilding the cache

It is also very handy, when you use multiple nested components to render pages: It can be difficult to track which pages are using the components, and which ones are not.

Requirements

  • Statamic 5.x
  • PHP 8.1 or higher(might work with lower versions)
  • Static caching must be enabled and configured to use the file driver

Installation

composer require f_roepstorf/static-cache-buster

For production environments, it's recommended to install with the --prefer-dist flag:

composer require f_roepstorf/static-cache-buster --prefer-dist

This ensures only the necessary files are installed, excluding development files like tests and configuration.

Usage

Run the cache buster command:

php artisan cache-buster:warm

Options

The command supports various options:

  • --queue: Queue the requests instead of processing them synchronously
  • --user=: HTTP authentication user
  • --password=: HTTP authentication password
  • --insecure: Skip SSL verification
  • --uncached: Only warm URLs that aren't currently cached
  • --max-depth=: Maximum depth of URLs to warm
  • --include=: Only warm specific URLs
  • --exclude=: Exclude specific URLs
  • --max-requests=: Maximum number of requests to warm

Nginx Configuration

If you're using Nginx with the default Statamic static caching setup, you'll need to add the following to your server configuration to properly handle the cache buster header:

set $try_location @static;

if ($request_method != GET) {
    set $try_location @not_static;
}

if ($args ~* "live-preview=(.*)") {
    set $try_location @not_static;
}

# Skip static cache when cache buster header is present
if ($http_x_statamic_cache_buster = "true") {
    set $try_location @not_static;
}

location / {
    try_files $uri $try_location;
}

location @static {
    try_files /static/${host}${uri}_$args.html $uri $uri/ /index.php?$args;
}

location @not_static {
    try_files $uri /index.php?$args;
}

This configuration ensures that requests with the X-Statamic-Cache-Buster header bypass the static cache and pass through to PHP.

License

This addon is open-source software licensed under the MIT license.

统计信息

  • 总下载量: 1.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固