slim / http-cache
Slim Framework HTTP cache middleware and service provider
Installs: 1 630 030
Dependents: 32
Suggesters: 2
Security: 0
Stars: 115
Watchers: 14
Forks: 25
Open Issues: 5
Requires
- php: ^7.2 || ^8.0
- psr/http-message: ^1.1 || ^2.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpstan/phpstan: ^1.3
- phpunit/phpunit: ^8.5.13 || ^9.3.8
- slim/psr7: ^1.1
- squizlabs/php_codesniffer: ^3.5
README
This repository contains a Slim Framework HTTP cache middleware and service provider.
Install
Via Composer
$ composer require slim/http-cache
Requires Slim 4.0.0 or newer.
Usage
declare(strict_types=1); use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; require __DIR__.'/../vendor/autoload.php'; $app = \Slim\Factory\AppFactory::create(); // Register the http cache middleware. $app->add(new \Slim\HttpCache\Cache('public', 86400)); // Create the cache provider. $cacheProvider = new \Slim\HttpCache\CacheProvider(); // Register a route and let the closure callback inherit the cache provider. $app->get( '/', function (Request $request, Response $response, array $args) use ($cacheProvider): Response { // Use the cache provider. $response = $cacheProvider->withEtag($response, 'abc'); $response->getBody()->write('Hello world!'); return $response; } ); $app->run();
Testing
$ phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email security@slimframework.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.