我想在开发环境中禁用结果缓存。
我不想在开发环境中评论缓存代码或删除它们。
有没有办法在开发环境中禁用缓存?
我将 SNCRedisBundle 和 Predis 用于带有 Redis 的 Symfony2。
示例单个结果代码:
$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();
第二个问题:
插入/更新后有什么方法可以清除缓存吗?我知道我可以使用生命周期事件,但我想知道是否还有其他可用的选项......
完整配置:
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://pw@/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