chanshige / slim-bodycache
This package is abandoned and no longer maintained.
No replacement package was suggested.
A slim middleware for Filesystem Cache based on symfony/cache
v0.0.3
2019-02-20 10:57 UTC
Requires
- php: >=7.1.0
- ext-json: *
- psr/http-message: ^1.0
- psr/simple-cache: ^1.0
Requires (Dev)
- phpmd/phpmd: *
- phpunit/phpunit: ^7.0
- slim/slim: ^3.0
- squizlabs/php_codesniffer: *
- symfony/cache: ^4.0
This package is auto-updated.
Last update: 2020-10-04 08:25:35 UTC
README
A slim middleware for Filesystem Cache based on symfony/cache.
Install
Via Composer
$ composer require chanshige/slim-bodycache
# symfony/cacheを使う場合はこちらも
$ composer require symfony/cache
Requires Slim 3.0.0 or newer.
Usage
<?php $app = new \Slim\App(); // CacheConfig $namespace = 'cache'; $defaultLifetime = 3600; $directory = '/path/to/dir'; // Symfony Filesystem Cache // PSR-6/16 Interfaceを持つコンポーネントを使用 $sfCache = new \Symfony\Component\Cache\Simple\FilesystemCache( $namespace, $defaultLifetime, $directory ); // Register middleware $app->add(new \Chanshige\Slim\BodyCache\Cache($sfCache)); // Fetch DI Container $container = $app->getContainer(); $container['body_cache'] = function () use ($sfCache) { return new \Chanshige\Slim\BodyCache\Cache($sfCache); }; // Json Response $app->get('/foo', function (\Slim\Http\Request $request, \Slim\Http\Response $response) { if($request->getAttribute('has_body_cache')) { return $response ->withHeader("Content-type", "application/json;charset=utf-8"); } return $response ->withStatus(200) ->withJson(['Hello World!!']); })->add($container->get('body_cache')); $app->run();
Contributing
We welcome bug reports, feature requests and pull requests through Slim-BodyCache Github issue tracker.
License
The Slim-BodyCache is licensed under the MIT license.