gpt4 book ai didi

Symfony - Controller 中的缓存(Memcache)

转载 作者:行者123 更新时间:2023-12-02 10:25:33 25 4
gpt4 key购买 nike

如何直接在 Controller 中使用缓存而无需查询(orm 缓存驱动程序)?

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

文档只提到了带有原则的缓存,但有时也需要没有原则的缓存。他们似乎没有提及任何相关内容,或者这是 Symfony 没有包装器的 View 之一?

最佳答案

安装和使用DoctrineCacheBundle :

  1. 将此 bundle 作为 Composer 依赖项添加到您的项目中:

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

    // 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

关于Symfony - Controller 中的缓存(Memcache),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36420509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com