tv2regionerne/statamic-cache

此包最新版本(dev-main)没有提供许可证信息。


README

Statamic Autocache 是一个插件,可以自动缓存任何部分的页面内容,以提高响应速度和选择性失效

如何安装

从您的项目根目录运行以下命令

composer require tv2regionerne/statamic-cache

然后运行迁移

php artisan migrate

您还可以选择发布配置

php artisan vendor:publish --tag=statamic-cache-config

如何使用

大多数情况下,插件会自动工作。它为部分、导航和集合标签添加钩子,以及增强条目和全局变量以确定哪些内容包含在哪些部分中。然后,这些数据被添加到数据库存储中,用于确定何时使缓存数据失效。

使用默认缓存,或者如果您想更控制何时清除,可以指定名为 statamic_autocache 的缓存存储。

中间件

autocache 中间件将自动添加到您的 web 中间件堆栈。如果您想将其添加到其他堆栈,只需添加

\Tv2regionerne\StatamicCache\Http\Middleware\Autocache::class

存储

该插件提供了一个用于与存储交互的门面:\Tv2regionerne\StatamicCache\Facades\Store

如果您想在存储中添加额外的数据,可以在 AppServiceProvider 中这样做,例如

MyTag::hook('init', function () {
	Store::mergeTags(['my_tag:id']);
});

确保在监听器中使标签失效

Store::invalidateContent(['my_tag:id']);

带有数据库索引的自定义缓存驱动程序

运行迁移以添加静态_cache 表。

此插件会自动将 redis_with_database 缓存驱动程序添加到您的 Statamic 安装中。要使用它,请将 config/statamic/static_caching.php 中的半措施静态缓存驱动程序更改为使用 redis_with_database,并确保 statamic.static_caching.strategy 设置为 half

'half' => [
    'driver' => 'redis_with_database',
    'expiry' => null,
],