sylweriusz / webcache-middleware
Static aka Html pages cache for Slim3 middleware stack
0.7.0
2021-02-19 01:27 UTC
Requires
- php: >=5.5.0
- guzzlehttp/psr7: ^1.2
README
Static pages cache for Slim3 middleware stack
WebCache will save only GET request with status 200.
Install
$ composer require sylweriusz/webcache-middleware
Usage
Declare middleware
$app->add(new \Slim\Middleware\WebcacheRedis('192.168.1.12:6379'));
Cache will try to detect ID of document, first numerical value in url parts.
Example: http://example.org/article/123456/title.html after detection ID = 123456
and if it fail to detect it will assume ID = 0
if You want to delete all articles with this ID You should do something like this
$webcache = new \Slim\Middleware\WebcacheRedis('192.168.1.12:6379'); $webcache->delete(123456);
Disabling cache inside application route
\Slim\Middleware\WebcacheRedis::setTtl(0);
Change default TTL (in seconds) inside application route
\Slim\Middleware\WebcacheRedis::setTtl(600);
Smarty plugin
Define parts of html that should be always fresh, no mather what.
<body> <div class="right-content"> {fresh id="reusable_box"}some html content{/fresh} </div>
You can even declare them empty (as readonly) on another page and hope it will just work.
<body> <div class="right-content"> {fresh id="reusable_box" readonly=1}{/fresh} </div>