dafiti / httpcache-listener
Dafiti HttpCache Response Listener for Silex Apps
This package's canonical repository appears to be gone and the package has been frozen as a result.
1.0.0
2016-06-23 18:03 UTC
Requires
- php: >=5.5.0
- symfony/event-dispatcher: ~2.3|3.0.*
- symfony/http-kernel: ~2.3|3.0.*
Requires (Dev)
- fabpot/php-cs-fixer: @stable
- phpunit/phpunit: @stable
- silex/silex: ~1.3.4
Suggests
- dafiti/config-service-provider: A simple way to manage config files in Silex
This package is not auto-updated.
Last update: 2021-06-23 09:03:52 UTC
README
Automatic set response headers (Etag and MaxAge) for Silex and Symfony Apps
Instalation
The package is available on Packagist. Autoloading is PSR-4 compatible.
{ "require": { "dafiti/httpcache-listener": "dev-master" } }
Usage
Basic - Silex
use Dafiti\Subscriber; use Pimple; use Silex\Application; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $app = new Application(); // You can use dafiti/config-service-provider to manage the config files $app['config'] = new Pimple(); $app['config']['http_cache'] = [ 'enabled' => true, 'etag' => true, 'max_age' => 100 ]; $app['dispatcher']->addSubscriber(new Subscriber\HttpCache($app['config']['http_cache'])); });
Basic - Symfony
# Register HttpCache configuration into config.yml: parameters: http_cache: enabled: false # If enabled, all routes will be cached max_age: 10 etag: true # Register subscriber into services.yml: httpcache_subscriber: class: Dafiti\Subscriber\HttpCache arguments: ['%http_cache%'] tags: - { name: kernel.event_subscriber } # Define the routes to be cached or not: app_index: path: '/' methods: [GET] defaults: _controller: AppBundle\Controller\DefaultController::indexAction http_cache: enabled: true max_age: 100 etag: false
License
MIT License