I'm testing Memcached on my Symfony2 application I set it to cache doctrine's queries, results and metadata:
我在我的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: Doctrine\Common\Cache\MemcacheCache
calls:
- [setMemcache, [@memcache]]
Until now, everything works fine.
到现在为止,一切正常。
I was wondering how does doctrine behaves if the Memcached server goes down. As far as I could see, the application breaks. In dev mode I get the following message:
我想知道如果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
注意:MemcachePool :: get():服务器localhost(tcp 11211,udp 0)失败:连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机无法响应而建立连接失败。 (10060)500内部服务器错误 - ContextErrorException
In production mode I'm also presented with an http 500.
在生产模式中,我还会看到一个http 500。
Is there a way to tell doctrine to bypass/ignore the Memcached server and go directly to the database, instead of returning 500s?
有没有办法告诉学说绕过/忽略Memcached服务器并直接进入数据库,而不是返回500?
1 个解决方案
#1
0
You can use The Second Level Cache
available in doctrine/orm 2.5
您可以使用doctrine / orm 2.5中提供的二级缓存
The idea to keep you default options for orm and add a memcache as second level cache:
保留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
When turned on, entities will be first searched in cache and if they are not found, a database query will be fired and then the entity result will be stored in a cache provider.
打开时,将首先在缓存中搜索实体,如果找不到它们,将触发数据库查询,然后实体结果将存储在缓存提供程序中。
#1
0
You can use The Second Level Cache
available in doctrine/orm 2.5
您可以使用doctrine / orm 2.5中提供的二级缓存
The idea to keep you default options for orm and add a memcache as second level cache:
保留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
When turned on, entities will be first searched in cache and if they are not found, a database query will be fired and then the entity result will be stored in a cache provider.
打开时,将首先在缓存中搜索实体,如果找不到它们,将触发数据库查询,然后实体结果将存储在缓存提供程序中。