zenstruck/cache-bundle

此包已被废弃且不再维护。没有推荐替代包。

为Symfony2提供httpcache预热命令

安装次数: 10,981

依赖者: 0

建议者: 0

安全: 0

星标: 39

关注者: 3

分支: 2

开放问题: 0

类型:symfony-bundle

v3.0.0 2016-02-01 20:37 UTC

This package is auto-updated.

Last update: 2020-10-28 14:26:46 UTC


README

Build Status Scrutinizer Code Quality Code Coverage StyleCI Latest Stable Version License

为Symfony2提供httpcache预热命令。该命令简单地在一个url列表上执行一个GET请求。必须注册一个或多个url提供者。此bundle需要一个php-http/httplugphp-http/message-factory的实现。

安装

  1. 添加到您的 composer.json

    $ composer require zenstruck/cache-bundle
    
  2. 使用Symfony2注册此bundle

    // app/AppKernel.php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Zenstruck\CacheBundle\ZenstruckCacheBundle(),
        );
        // ...
    }

配置

必须配置一个 http_client(实现 Http\Client\HttpClient 的类或服务)和一个 message_factory(实现 Http\Message\MessageFactory 的类或服务)。

zenstruck_cache:
    http_client:    Acme\MyHttpClient    # or a service (acme.my_http_client)
    message_factory: Acme\MyMessageFactory # or a service (acme.my_message_factory)

HttpCache预热命令

用法

app/console zenstruck:http-cache:warmup

网站地图提供者

此bundle附带一个URL提供者,它会查看一个网站地图列表以检索URL列表。如果给定一个没有网站地图或网站地图索引的URL,提供者首先查找{url}/sitemap_index.xml以找到一组网站地图文件。如果没有找到索引,则默认使用{url}/sitemap.xml

要启用网站地图提供者,请在您的 config.yml 中进行配置。

zenstruck_cache:
    sitemap_provider:
        sitemaps:
            - http://example.com/sitemap.xml # detects if sitemap or sitemap index and act accordingly
            - http://example.com/en/sitemap.xml # same as above
            - http://www.example.com # trys http://example.com/sitemap_index.xml and http://example.com/sitemap.xml

添加自定义URL提供者

  1. 创建一个实现 Zenstruck\CacheBundle\Url\UrlProvider 的类

    use Zenstruck\CacheBundle\Url\UrlProvider;
    
    namespace Acme;
    
    class MyUrlProvider implements UrlProvider
    {
        public function getUrls()
        {
            $urls = array();
    
            // fetch from a datasource
    
            return $urls;
        }
    
        public function count()
        {
            return count($this->getUrls());
        }
    }
  2. 将类注册为带有 zenstruck_cache.url_provider 标签的服务

    my_url_provider:
        class: Acme\MyUrlProvider
        tags:
            - { name: zenstruck_cache.url_provider }

完整默认配置

zenstruck_cache:
    # Either a class or a service that implements Http\Client\HttpClient.
    http_client:              ~ # Required

    # Either a class or a service that implements Http\Message\MessageFactory.
    message_factory:          ~ # Required

    sitemap_provider:
        enabled:              false
        sitemaps:             []