本文整理匯總了PHP中Doctrine\ORM\Query::useResultCache方法的典型用法代碼示例。如果您正苦於以下問題:PHP Query::useResultCache方法的具體用法?PHP Query::useResultCache怎麽用?PHP Query::useResultCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\Query
的用法示例。
在下文中一共展示了Query::useResultCache方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: cacheQuery
/**
* return query in cache
*
* @param Query $query
* @param integer $time
* @param string $MODE [MODE_GET, MODE_PUT , MODE_NORMAL , MODE_REFRESH]
* @param boolean $setCacheable
* @param string $namespace
* @param string $input_hash
*
* @return Query
* @access public
* @author Etienne de Longeaux <etienne.delongeaux@gmail.com>
*/
public function cacheQuery(Query $query, $time = 3600, $MODE = 3, $setCacheable = true, $namespace = '', $input_hash = '')
{
if (!$query) {
throw new \Gedmo\Exception\InvalidArgumentException('Invalide query instance');
}
// create single file from all input
if (empty($input_hash)) {
$input_hash = $namespace . sha1(serialize($query->getParameters()) . $query->getSQL());
}
$query->useResultCache(true, $time, (string) $input_hash);
$query->useQueryCache(true);
if (method_exists($query, 'setCacheMode')) {
$query->setCacheMode($MODE);
}
if (method_exists($query, 'setCacheable')) {
$query->setCacheable($setCacheable);
}
return $query;
}
示例2: getOneResult
public function getOneResult(\Doctrine\ORM\Query $query, $cacheId = null, $useCache = false)
{
$query->useResultCache($useCache, $this->cacheDuration, $cacheId);
return $query->getOneOrNullResult();
}
示例3: setQueryOptions
/**
* Set the query options
*
* @param \Doctrine\ORM\Query $query
* @param array $options
*/
protected function setQueryOptions(Query $query, array $options = null)
{
if (!$options) {
return;
}
if (isset($options['result_cache'])) {
if (is_array($options['result_cache'])) {
foreach ($options['result_cache'] as $key => $value) {
switch ($key) {
case 'enabled':
$query->useResultCache($value);
break;
case 'lifetime':
$query->setResultCacheLifetime($value);
break;
case 'id':
$query->setResultCacheId($value);
break;
}
}
}
}
}