bnomei / kirby-content-last-modified
Kirby 插件,用于跟踪完整内容文件夹中任何内容最后修改的时间戳。
1.0.0
2024-09-20 09:03 UTC
Requires
- php: >=8.2
- getkirby/composer-installer: ^1.2
Requires (Dev)
- getkirby/cms: ^4.4.0
- laravel/pint: ^1.13
- pestphp/pest: ^2.24
- spatie/ray: ^1.39
README
Kirby 插件,用于跟踪完整内容文件夹中任何内容最后修改的时间戳。
商业使用
支持开源!
此插件免费,但如果您将其用于商业项目,请考虑赞助我或进行捐赠。
如果我的工作帮助您赚了一些钱,那么我认为我可能也应该得到一点回报,对吧?
友善一点。分享一点。谢谢。
—— Bruno
安装
- 将 master.zip 解压为文件夹
site/plugins/kirby-content-last-modified
或 - 使用
git submodule add https://github.com/bnomei/kirby-content-last-modified.git site/plugins/kirby-content-last-modified
或 使用
composer require bnomei/kirby-content-last-modified
使用
安装此插件后,它将在 Kirby 安装内容的 content
文件夹中创建一个文件。如果 content
文件夹中的任何内容(网站、页面、文件)发生变化,该文件将存储修改发生的时间戳。这可能会在无效化缓存或触发其他操作时很有用。
输出最后修改时间戳
<?= site()->contentLastModified()->toDate('c') ?>
如果内容在给定时间戳之后被修改,则刷新缓存
<?php // http://example.com/some-page?last-modified=1726822135 if (site()->contentLastModified()->toInt() > intval(get('last-modified'))) { kirby()->cache('my-cache')->flush(); }
根据最后修改时间戳使单个缓存值无效
<?php $lastModifiedTimestamp = site()->contentLastModified()->toInt(); /* @var $cache \Kirby\Cache\Cache */ $cache = kirby()->cache('your-cache-name'); /* @var $rawValue \Kirby\Cache\Value */ $rawValue = $cache->retrieve('some-cache-key'); if ($rawValue && $rawValue->created() < $lastModifiedTimestamp) { $cache->remove('some-cache-key'); } // or with the helper site()->removeFromCacheIfCreatedIsAfterModified('your-cache-name', 'some-cache-key', $lastModifiedTimestamp); // defaults to site()->contentLastModified()->toInt() site()->removeFromCacheIfCreatedIsAfterModified('your-cache-name', 'some-cache-key');
性能
核心方法 site()->modified()
将返回相同的时间戳,但它将遍历所有内容文件,这可能不是最有效的方法,具体取决于您有多少内容。
设置
免责声明
此插件“按原样”提供,不提供任何保证。自行承担使用风险,并在使用生产环境之前自行测试。
许可证
不建议在任何推广种族主义、性别歧视、恐同、动物虐待、暴力或其他仇恨言论的项目中使用此插件。