liip/doctrine-cache-bundle

此包已被废弃,不再维护。作者建议使用 doctrine/doctrine-cache-bundle 包。

此Bundle提供了Doctrine Common Cache层与Symfony2的集成。

安装次数: 468,275

依赖项: 8

建议者: 3

安全性: 0

星标: 72

关注者: 47

分支: 14

开放问题: 0

类型:symfony-bundle

1.0.4 2014-02-17 02:17 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:20:04 UTC


README

此Bundle提供了Doctrine Common Cache层与Symfony2的集成。

此项目已被弃用

This Project Has Been Deprecated in favor of doctrine/doctrine-cache-bundle.

改为使用 https://github.com/doctrine/DoctrineCacheBundle

安装

1. 将Bundle添加到你的composer.json文件中

"require": {
    ...
    "liip/doctrine-cache-bundle": "~1.0"
}

2. 使用composer安装Bundle

$ php composer.phar update liip/doctrine-cache-bundle

3. 将此Bundle添加到应用kernel中

<?php
// application/ApplicationKernel.php
public function registerBundles()
{
  return array(
      // ...
      new Liip\DoctrineCacheBundle\LiipDoctrineCacheBundle(),
      // ...
  );
}

配置

简单配置任意数量的缓存服务

# app/config.yml
liip_doctrine_cache:
    namespaces:
        # name of the service (aka liip_doctrine_cache.ns.foo)
        foo:
            # cache namespace is "ding", this is optional
            namespace: ding
            # cache type is "apc"
            type: apc
            # alias names of the service (liip_doctrine_cache.ns.foo_bar and liip_doctrine_cache.ns.foo_baz)
            alias: [foo_bar,foo_baz]
        # name of the service (aka liip_doctrine_cache.ns.lala) and namespace
        lala:
            # cache type is "file_system"
            type: file_system
            # optionally define a directory
            directory: /tmp/lala
            # single alias name (equivalent to `alias: [lala_bar]`)
            alias: lala_bar
        # name of the service (aka liip_doctrine_cache.ns.bar)
        bar:
            # cache namespace is "dong"
            namespace: dong
            # cache type is "memcached"
            type: memcached
            # name of a service of class Memcached that is fully configured (optional)
            id: my_memcached_service
            # port to use for memcache(d) (default is 11211)
            port: 11211
            # host to use for memcache(d) (default is localhost)
            host: localhost

服务默认值在编译器通过中定义: https://github.com/liip/LiipDoctrineCacheBundle/blob/master/DependencyInjection/Compiler/ServiceCreationCompilerPass.php

用法

简单地在依赖注入配置文件中使用 liip_doctrine_cache.ns.[your_name],或在代码中使用 $container->get('liip_doctrine_cache.ns.[your_name]')

自定义缓存类型

通过定义名为 liip_doctrine_cache.[type name] 的服务来定义一个新的类型。注意,该服务需要实现 Doctrine\Common\Cache\Cache 接口。

开发模式

在开发模式下,你不希望在多个请求之间缓存东西。一个简单的解决方案是在开发环境中使用数组缓存。

#config.yml
liip_doctrine_cache:
    namespaces:
        presta_sitemap:
            type: file_system

# config_dev.yml
liip_doctrine_cache:
    namespaces:
        presta_sitemap:
            type: array

数组缓存将在每个请求后丢失,因此只有当你在一个请求中访问相同的数据时,才有效缓存。