Created
January 29, 2013 15:48
-
-
Save liuggio/4665238 to your computer and use it in GitHub Desktop.
Cached repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tvision\Bundle\BookingCoreBundle\Repository; | |
/** | |
* | |
* usage | |
* Class MyRepository extends CachedRepository | |
* $query->setMaxResults(1); | |
* $this->setCache($query, __METHOD__); | |
*/ | |
use Doctrine\ORM\EntityRepository; | |
use Doctrine\ORM\AbstractQuery; | |
abstract class CachedRepository extends EntityRepository | |
{ | |
CONST DEFAULT_LIFETIME = 240; | |
public function setCache(AbstractQuery $query, $prefix, $lifetime = self::DEFAULT_LIFETIME) | |
{ | |
$key = serialize($query->getParameters()); | |
$query->useResultCache(true, $lifetime , $prefix.$key); | |
$query->useQueryCache(true); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment