├── .gitignore ├── _config.yml ├── renovate.json ├── composer.json ├── .php_cs ├── LICENSE ├── README.md └── src └── Middleware └── CacheResponse.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /*.cache 3 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flc/laravel-middleware-cache-response", 3 | "description": "Laravel中间件-Response缓存", 4 | "keywords": ["laravel", "flc", "middleware", "cache", "response", "中间件", "缓存"], 5 | "type": "library", 6 | "license": "MIT", 7 | "require": { 8 | "php": ">=5.4.0" 9 | }, 10 | "autoload": { 11 | "psr-4": { 12 | "Flc\\Laravel\\Http\\": "src/" 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | setRiskyAllowed(true) 5 | ->setRules(array( 6 | '@Symfony' => true, 7 | 'array_syntax' => array('syntax' => 'short'), 8 | 'ordered_imports' => true, 9 | 'no_useless_else' => true, 10 | 'no_useless_return' => true, 11 | 'php_unit_construct' => true, 12 | 'php_unit_strict' => true, 13 | 'yoda_style' => false, 14 | 'phpdoc_summary' => false, 15 | )) 16 | ->setFinder( 17 | PhpCsFixer\Finder::create() 18 | ->exclude('vendor') 19 | ->in(__DIR__) 20 | ) 21 | ; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 叶子坑(http://flc.ren | http://flc.io) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel中间件-Response缓存 2 | 3 | [](https://packagist.org/packages/flc/laravel-middleware-cache-response) 4 | [](https://packagist.org/packages/flc/laravel-middleware-cache-response) 5 | [](https://packagist.org/packages/flc/laravel-middleware-cache-response) 6 | [](https://996.icu) 7 | [](https://github.com/996icu/996.ICU/blob/master/LICENSE) 8 | 9 | ## 功能 10 | 11 | - 支持缓存渲染后数据 12 | - 支持指定缓存过期时间(默认10分钟) 13 | - header头输出缓存命中状态、缓存Key及过期时间 14 | 15 | ## 安装 16 | 17 | ```sh 18 | composer require flc/laravel-middleware-cache-response 19 | ``` 20 | 21 | ## 配置 22 | 23 | > `\app\Http\Kernel.php`文件中`$routeMiddleware`增加: 24 | 25 | ```php 26 | \Flc\Laravel\Http\Middleware\CacheResponse::class, 28 | 29 | // cache.response 命名随意,你开心就好 30 | ``` 31 | 32 | ## 使用 33 | 34 | ```php 35 | middleware('cache.response'); 39 | 40 | Route::get('/', function () { 41 | return view('welcome'); 42 | })->middleware('cache.response:20'); // 指定缓存时间20分钟 43 | ``` 44 | 45 | ## 附录 46 | 47 | **缓存规则** 48 | 49 | - 当前URL全路径md5 50 | 51 | **Headers** 52 | 53 | ``` 54 | X-Cache:Missed 55 | X-Cache-Expires:2018-03-29 15:08:29 CST 56 | X-Cache-Key:6c9b19774e2c304a42d200f314d8c80b 57 | ``` 58 | 59 | ## TODO 60 | 61 | - 增加`status`、`header`的支持 62 | 63 | 64 | ## 捐赠 65 | 66 | 如果你觉得本扩展对你有帮助,请捐赠以表支持,谢谢~~ 67 | 68 |
![]() 微信 |
71 | ![]() 支付宝 |
72 |