swisnl / laravel-static-request-cache
1.5.0
2023-02-16 18:54 UTC
Requires
- php: ^7.2|^8.0
- laravel/framework: ^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- graham-campbell/testbench: ^5.7
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.0|^9.5
- squizlabs/php_codesniffer: ^2.3
README
🚨 此包已被弃用 🚨
我们不再在我们自己的项目中使用此包——我们已经切换到带有FastCGI缓存的Nginx——并且不能再证明维护它所需的时间。这就是我们选择弃用的原因。请随意fork我们的代码并维护自己的副本,或者使用许多替代方案之一。我们建议使用silber/page-cache作为替代,因为它相当相似。
安装
通过Composer
$ composer require swisnl/laravel-static-request-cache
设置
将中间件添加到你的 Http/Kernel.php
中间件数组的末尾。
protected $middleware = [ \Swis\Laravel\StaticRequestCache\Http\Middleware\CacheMiddleware::class, ];
将以下片段添加到你的 .htaccess
# Rewrite to html cache if it exists and the request is for a static page
# (no url query params and only get requests)
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{DOCUMENT_ROOT}/static/html%{REQUEST_URI} -f
RewriteRule ^(.*)$ /static/html%{REQUEST_URI} [L]
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{DOCUMENT_ROOT}/static/html%{REQUEST_URI}/index.html -f
RewriteRule ^(.*)$ /static/html%{REQUEST_URI}/index.html [L]
禁用
如果你因为某些原因(内容可能为动态)想禁用缓存,你可以在IoC中使用StaticRequestCache单例。
public function __construct(StaticRequestCache $staticRequestCache) { $this->staticRequestCache = $staticRequestCache; $this->staticRequestCache->disable(); }
或者使用Facade
StaticRequestCache::disable();
请注意,此包还会检查Cache-control头部并相应地缓存。你可以通过编辑non_cacheable_cache_control_values
来更改此行为。
清除文件
要手动清除所有文件,可以使用Artisan命令。
$ php artisan static-html-cache:clear
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
测试
$ composer test
贡献
请参阅CONTRIBUTING和CODE_OF_CONDUCT以获取详细信息。
安全
如果你发现任何与安全相关的问题,请通过电子邮件security@swis.nl联系,而不是使用问题跟踪器。
致谢
基于mscharl/laravel-static-html-cache。增加了可缓存内容类型和非缓存缓存控制值的配置。
许可
MIT许可证(MIT)。请参阅许可证文件获取更多信息。
此软件包属于Treeware。如果您在生产环境中使用它,我们请求您为世界种一棵树以感谢我们的工作。通过为Treeware森林做出贡献,您将为当地家庭创造就业机会并恢复野生动物栖息地。
SWIS ❤️ 开源
SWIS 是一家来自荷兰莱顿的网页设计公司。我们热爱与开源软件合作。