php - LswMemcacheBundle 中的缓存生命周期

标签 php symfony doctrine-orm memcached lsw-memcache-bundle

我决定使用 LswMemcacheBundle(在 Symfony2 中)将 Doctrine2 查询缓存到 memcached 中,但我遇到了一个问题。我找不到任何关于更改缓存生命周期的可能性的信息,甚至是关于默认生命周期的信息。

有没有人可以提供给我这样的信息?

最佳答案

看起来结果缓存并未为所有查询启用(但查询缓存已启用),我们需要使用 useResultCache 方法启用它。此方法还允许我们设置缓存生命周期。

所以它看起来像这样

$em->createQuery('SELECT a FROM SomeBundle:Entity a')
      ->useResultCache(true, 3600, 'cacheId')
      ->getResult();

createQueryBuilder

$repository = $this->getEntityManager()->getRepository('SomeBundle:Entity');
$qb = $repository->createQueryBuilder('g');
$qb->andWhere('g.categoryId = :categoryId')->setParameter('categoryId', '1');
$qb->addOrderBy('g.id', 'DESC');

$query = $qb->getQuery();
$query->useResultCache(true, 3600, 'cacheId');

3600 是缓存生命周期(以秒为单位),cacheId 是我们的缓存键。

关于php - LswMemcacheBundle 中的缓存生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19436890/

相关文章:

php - 在表问题中执行 PHP 脚本的按钮

php - 了解参数化查询中 i 和 s 之间的含义

jquery - 如何在 TWIG (symfony2) 中使用 JQuery

jquery - 如何将 twig {{path ('' )}} 调用渲染为 jquery ajax url

symfony - Symfony2 命名空间的文档

php - 使用 Ajax 从 JSON Web 服务检索数据

php - 获取正则表达式组中匹配字符的数量

php - Symfony 4 FosUserBundle Controller 装饰

php - Doctrine Query Builder 选择 Count with Case

php - Symfony2,Doctrine2 - 强制更新 - 表已经存在于多对多关系中