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

This package is not auto-updated.

Last update: 2021-06-23 09:03:52 UTC


README

Build Status Scrutinizer Code Quality Code Coverage HHVM Latest Stable Version Total Downloads License

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