1
我想在开发环境中禁用结果缓存。开发环境禁用结果缓存(Redis) - Symfony2
我不想评论缓存代码或在开发环境中删除它们。
有什么办法可以在dev env上禁用缓存?
我正在使用SNCRedisBundle & Predis for Symfony2 with Redis。
样品单结果代码:
$em = $this->container->get('doctrine')->getManager();
$predis = new \Snc\RedisBundle\Doctrine\Cache\RedisCache();
$predis->setRedis(new \Predis\Client());
$qb = $em->createQueryBuilder();
$qb
->select('s')
->from('CSSliderBundle:Slider', 's')
->where($qb->expr()->eq('s.title', ':title'))
->setParameter('title', $title);
$slider = $qb
->getQuery()
->useResultCache(true, 3600 * 1.5) // added this line
->setResultCacheDriver($predis)
->setResultCacheLifetime(86400)
->getOneOrNullResult();
而第二个问题:
有什么办法来清除插入/更新后的缓存教义内置的?我知道我可以使用lifecycleevents但我不知道如果有任何其他选项...
全部配置:
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost
logging: %kernel.debug%
options:
prefix: "%redis_prefix%"
cache:
type: predis
alias: cache
dsn: redis://localhost/1
logging: true
options:
prefix: "%redis_prefix%"
cluster:
type: predis
alias: cluster
dsn:
- redis://127.0.0.1/2
- redis://127.0.0.2/3
- redis://[email protected]/var/run/redis/redis-1.sock/4
- redis://127.0.0.1:6379/5
options:
profile: 2.4
connection_timeout: 10
connection_persistent: true
read_write_timeout: 30
iterable_multibulk: false
throw_errors: true
cluster: Snc\RedisBundle\Client\Predis\Connection\PredisCluster
monolog:
type: predis
alias: monolog
dsn: redis://localhost/6
logging: false
options:
connection_persistent: true
session:
client: default
use_as_default: true
doctrine:
metadata_cache:
client: cache
entity_manager: default
document_manager: default
result_cache:
client: cache
entity_manager: default
namespace: "doctrine_result_cache_%kernel.environment%_"
query_cache:
client: cache
entity_manager: default
monolog:
client: monolog
key: monolog
swiftmailer:
client: default
key: swiftmailer
没有工作...在我添加了一条记录后,仍然有相同的结果... – 2014-08-28 12:32:27
@ R.CanserYanbakan,使用'$ query-> useResultCache(true,3600 * 1.5);'为您的查询。 – 2014-08-28 12:38:35
兄弟,我会更新我的问题与您的代码,但仍然不工作... – 2014-08-28 12:43:21