dafiti/httpcache-listener

Dafiti HttpCache 响应监听器,适用于 Silex 应用程序

此软件包的官方仓库似乎已消失,因此该软件包已被冻结。

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

为 Silex 和 Symfony 应用程序自动设置响应头(Etag 和 MaxAge)

安装

此软件包可在 Packagist 上找到。支持 PSR-4 自动加载。

{
    "require": {
        "dafiti/httpcache-listener": "dev-master"
    }
}

用法

基础 - 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']));
});

基础 - 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

许可

MIT 许可证