sylweriusz / webcache-middleware
用于 Slim3 中间件栈的静态 HTML 页面缓存
0.7.0
2021-02-19 01:27 UTC
Requires
- php: >=5.5.0
- guzzlehttp/psr7: ^1.2
README
用于 Slim3 中间件栈的静态页面缓存
WebCache 只会保存状态为 200 的 GET 请求。
安装
$ composer require sylweriusz/webcache-middleware
使用方法
声明中间件
$app->add(new \Slim\Middleware\WebcacheRedis('192.168.1.12:6379'));
缓存将尝试检测文档 ID,即 URL 部分中的第一个数字值。
示例: http://example.org/article/123456/title.html 检测后 ID = 123456
如果检测失败,将默认 ID = 0
如果您想删除具有此 ID 的所有文章,您应该这样做
$webcache = new \Slim\Middleware\WebcacheRedis('192.168.1.12:6379'); $webcache->delete(123456);
在应用程序路由中禁用缓存
\Slim\Middleware\WebcacheRedis::setTtl(0);
在应用程序路由中更改默认 TTL(以秒为单位)
\Slim\Middleware\WebcacheRedis::setTtl(600);
Smarty 插件
定义始终需要新鲜的 HTML 部分
<body> <div class="right-content"> {fresh id="reusable_box"}some html content{/fresh} </div>
您甚至可以声明它们为空(只读)在另一页面上,并希望它正常工作。
<body> <div class="right-content"> {fresh id="reusable_box" readonly=1}{/fresh} </div>