Symfony-控制器中的缓存(Memcache)

bad

如何在不查询的情况下直接在控制器中使用缓存(orm缓存驱动程序)?

http://symfony.com/doc/current/reference/configuration/doctrine.html#caching-drivers

这些文档只提到了使用学说的缓存,但是有时需要没有学说的缓存。他们似乎没有提及任何东西,还是Symfony没有包装的观点之一?

PawełMikołajczuk

安装并使用DoctrineCacheBundle

  1. 将此束作为作曲家依赖项添加到您的项目中:

    composer require doctrine/doctrine-cache-bundle
    
  2. 将此捆绑包添加到您的应用程序内核中:

    // app/AppKernel.php
    public function registerBundles()
    {
        // ...
        $bundles[] = new \Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle();
    
        return $bundles;
    }
    
  3. 配置它:

    # app/config/config.yml
    doctrine_cache:
        providers:
            my_apc_metadata_cache:
                type: apc
                namespace: metadata_cache_ns
            my_apc_query_cache:
                namespace: query_cache_ns
                apc: ~
            memcache:
                servers:
                    memcache01: 11211
    
  4. 用它:

    $apcCache = $this->container->get('doctrine_cache.providers.my_apc_cache');
    $memcacheCache = $this->container->get('doctrine_cache.providers.memcache');
    

了解更多:https : //symfony.com/doc/current/bundles/DoctrineCacheBundle/usage.html完整的提供程序参考:http : //symfony.com/doc/current/bundles/DoctrineCacheBundle/reference.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章