加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如果服务器脱机,如何告诉doctrine忽略Memcached?

发布时间:2020-12-13 22:25:52 所属栏目:PHP教程 来源:网络整理
导读:我在我的Symfony2应用程序上测试Memcached 我将其设置为缓存doctrine的查询,结果和元数据: orm: entity_managers: default: metadata_cache_driver: type: service id: doctrine.cache.memcache2 query_cache_driver: type: service id: doctrine.cache.mem
我在我的Symfony2应用程序上测试Memcached
我将其设置为缓存doctrine的查询,结果和元数据:

orm:
    entity_managers:
        default:
            metadata_cache_driver:
                type: service
                id: doctrine.cache.memcache2
            query_cache_driver:
                type: service
                id: doctrine.cache.memcache2
            result_cache_driver:
                type: service
                id: doctrine.cache.memcache2

services:
    memcache:
        class: Memcache
        calls:
            - [ addserver,[ 'localhost',11211 ]]

    doctrine.cache.memcache2:
        class: DoctrineCommonCacheMemcacheCache
        calls:
            - [setMemcache,[@memcache]]

到现在为止,一切正常.

我想知道如果Memcached服务器出现故障,学说会如何表现.据我所知,应用程序中断了.在开发模式下,我收到以下消息:

Notice: MemcachePool::get(): Server localhost (tcp 11211,udp 0) failed with: A connection attempt failed because the connected party did not properly respond after a period of time,or established connection failed because connected host has failed to respond.
(10060)
500 Internal Server Error – ContextErrorException

在生产模式中,我还会看到一个http 500.

有没有办法告诉学说绕过/忽略Memcached服务器并直接转到数据库,而不是返回500?

解决方法

您可以使用doctrine / orm 2.5中提供的二级缓存

看到:
http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html

保留orm的默认选项并将memcache添加为二级缓存的想法:

orm:
     entity_managers:
        default:
           auto_mapping:  true
           second_level_cache:
               region_cache_driver:
                  type:                 service
                  id:                   doctrine.cache.memcache2
               enabled:              true
               regions:
                  region_name:
                       cache_driver:
                           type:                 service
                           id:                   doctrine.cache.memcache2

启用后,将首先在缓存中搜索实体,如果找不到实体,则会触发数据库查询,然后实体结果将存储在缓存提供程序中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读