Kohana DB - 使用SQL_CACHE

时间:2012-03-29 07:11:29

标签: mysql caching kohana

有没有办法用Kohana的(3.x)数据库查询构建器实现它:

SELECT SQL_CACHE id, name FROM customer;

我知道我可以使用缓存方法来缓存mysql结果,但是我希望mysql缓存结果,而不是Kohana。

1 个答案:

答案 0 :(得分:1)

我不认为kohana在任何地方都定义了SQL_CACHE。但如果你觉得show停止只是因为kohana没有sql_cache,我可以建议你。制作自己的sql_cache方法非常简单。

在modules / database / classes / kohana / database / query / builder / select.php中定义$ _sqlcache变量。就像“protected $ _distinct = FALSE;”

一样
protected $_sqlcache = FALSE;

添加方法

public function sqlcache($value)
{
    $this->_sqlcache = (bool) $value;    
    return $this;
}

在compile()方法中

//Just below these lines
/*if ($this->_distinct === TRUE)
{
    // Select only unique results
    $query .= 'DISTINCT ';
}*/

if ($this->_sqlcache === TRUE)
{
    $query .= 'SQL_CACHE ';
}

//$query = DB::select('id', 'name')->sqlcache(TRUE)->from('customer');

我在Kohana 3.2中做了这个,它确实产生了一个像你要求的查询,但我不确定它是否是正确的方法。如果有效,请告诉我。