【发布时间】:2016-08-12 16:29:40
【问题描述】:
我刚刚使用以下配置在我的 symfony 应用程序上启用了查询缓存:
Doctine 缓存配置
doctrine_cache:
providers:
cache:
namespace: '%cache_namespace%'
chain:
providers:
- array_cache
- redis_cache
- file_cache
redis_cache:
namespace: '%cache_namespace%'
predis:
host: "%redis_host%"
port: "%redis_port%"
password: "%redis_password%"
timeout: "%redis_timeout%"
array_cache:
namespace: '%cache_namespace%'
array: ~
file_cache:
namespace: '%cache_namespace%'
file_system:
directory: "%kernel.cache_dir%/application"
Doctrine ORM 配置
orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
an_entity_manager:
connection: connection
mappings:
AppBundle: ~
naming_strategy: doctrine.orm.naming_strategy.underscore
metadata_cache_driver:
type: service
id: "doctrine_cache.providers.cache"
query_cache_driver:
type: service
id: "doctrine_cache.providers.cache"
result_cache_driver:
type: service
id: "doctrine_cache.providers.cache"
我还进行了填充本地 sqlite 数据库而不是真实数据库的功能测试。我看到的是以下内容:
每次我运行测试时,我都会看到 Redis 缓存会创建新的键,即使是相同的记录也是如此。我猜这一定是因为在执行每个测试之前都会重新创建数据库,并且就缓存而言,新创建的行的内容并不重要,但我不能确定。
有谁知道这是否是预期的行为?
【问题讨论】:
-
您的问题看起来有点令人困惑,因为您没有在这里进行单元测试。在真正的单元测试中,你会模拟你的连接,因为你不是在测试那个,而是你最小的可测试单元。
-
你说得对,我实际上是指功能测试。将编辑问题