Skip to content

Instantly share code, notes, and snippets.

@eb-eoliveira
Created April 18, 2013 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eb-eoliveira/5413804 to your computer and use it in GitHub Desktop.
Save eb-eoliveira/5413804 to your computer and use it in GitHub Desktop.
final public function findReadOnly($id, $fetchMode = self::FETCH_LAZY_MODE)
{
// initialize answer
$res = null;
// calculate key
$cacheKey = self::getCacheKey($this->getEntityName(), $id, $fetchMode);
// check cache
if (($cacheRes = $this->fetchFromCache($cacheKey)) !== false) {
// cache hit
$res = $this->getEntityManager()->merge($cacheRes);
// just for debug purposes
if ($this->logger instanceof LoggerInterface) {
$this->logger->debug('Find read only entity cache hit ' . $cacheKey);
}
} elseif (is_object($dbRes = $this->findReadOnlyDb($id, $fetchMode))) {
// store into cache
$this->storeIntoCache(
$cacheKey,
$dbRes,
$this->getExpiration($fetchMode)
);
$res = $dbRes;
}
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment