richan-fongdasen / laravel-varnishable
Laravel中简单易用的Varnish集成
2.2.0
2024-03-13 04:39 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/database: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- ekino/phpstan-banned-code: ^1.0
- larastan/larastan: ^1.0|^2.0
- mockery/mockery: ^1.4
- orchestra/testbench: ^6.0|^7.0|^8.0|9.x-dev
- phpmd/phpmd: ^2.11
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- phpunit/phpunit: ^9.5|^10.0|^11.0
README
Laravel Varnishable
Laravel中简单易用的Varnish集成
摘要
本包提供了一种简单的方法,将您的Laravel应用程序与Varnish缓存集成。
目录
设置
通过Composer安装包
$ composer require richan-fongdasen/laravel-varnishable
Laravel版本兼容性
如果您使用的是Laravel版本5.5+,则可以跳过在Laravel应用程序中注册服务提供者。
服务提供者
在config/app.php
中添加包的服务提供者
'providers' => [ // ... RichanFongdasen\Varnishable\ServiceProvider::class, ];
别名
在config/app.php
中添加包的别名
'aliases' => [ // ... 'Varnishable' => RichanFongdasen\Varnishable\Facade::class, ];
发布包资产
使用以下php artisan
命令发布包资产文件
$ php artisan vendor:publish --provider="RichanFongdasen\Varnishable\ServiceProvider"
上述命令会在您的应用程序配置目录中创建新的varnishable.php
文件。
配置
return [ /* |-------------------------------------------------------------------------- | Varnish hosts |-------------------------------------------------------------------------- | | Specify the hostnames of your varnish instances. You can use array | to specify multiple varnish instances. | */ 'varnish_hosts' => env('VARNISH_HOST', '127.0.0.1'), /* |-------------------------------------------------------------------------- | Varnish port |-------------------------------------------------------------------------- | | Specify the port number that your varnish instances are listening to. | */ 'varnish_port' => env('VARNISH_PORT', 6081), /* |-------------------------------------------------------------------------- | Cache duration |-------------------------------------------------------------------------- | | Specify the default varnish cache duration in minutes. | */ 'cache_duration' => env('VARNISH_DURATION', 60 * 24), /* |-------------------------------------------------------------------------- | Cacheable header |-------------------------------------------------------------------------- | | Specify the custom HTTP header that we should add, so Varnish can | recognize any responses containing the header and cache them. | */ 'cacheable_header' => 'X-Varnish-Cacheable', /* |-------------------------------------------------------------------------- | Uncacheable header |-------------------------------------------------------------------------- | | Specify the custom HTTP header that we should add, so Varnish won't | cache any reponses containing this header. | */ 'uncacheable_header' => 'X-Varnish-Uncacheable', /* |-------------------------------------------------------------------------- | Use ETag Header |-------------------------------------------------------------------------- | | Please specify if you want to use ETag header for any of your static | contents. | */ 'use_etag' => true, /* |-------------------------------------------------------------------------- | Use Last-Modified Header |-------------------------------------------------------------------------- | | Please specify if you want to use Last-Modified header for any of your | static contents. | */ 'use_last_modified' => true, /* |-------------------------------------------------------------------------- | ESI capability header |-------------------------------------------------------------------------- | | Please specify the ESI capability header that the varnish server would | send if there is any ESI support. | */ 'esi_capability_header' => 'Surrogate-Capability', /* |-------------------------------------------------------------------------- | ESI reply header |-------------------------------------------------------------------------- | | Please specify the HTTP header that you want to send as a reply | in response to ESI capability header which the varnish server sent in | current request. | */ 'esi_reply_header' => 'Surrogate-Control', ];
使用方法
本节正在建设中。
致谢
- spatie/laravel-varnish - 本仓库中的一些概念受到了此包的启发。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。