2

我在 cakephp 中有一个站点,并且为它配置了缓存。在 bootstrap.php 中,我像 cakephp 网站中的指南一样编写了这一行:

Cache::config('default', array('engine' => 'File'));

Cache::config('short', array(
    'engine' => 'File',
    'duration' => '+1 hours',
    'path' => CACHE,
    'prefix' => 'cake_short_'
));

// long
Cache::config('long', array(
    'engine' => 'File',
    'duration' => '+1 week',
    'probability' => 100,
    'path' => CACHE . 'long' . DS,
));

在我的控制器中,我想缓存一些多次调用的查询,如下所示:

class User extends AppModel {

    public function get($alias) {
        $result = Cache::read('get_users', 'longterm');
        if (!$result) {
            $result = $this->find('all', array('conditions' =>array( 'alias' => $alias)));
            Cache::write('get_users', $result, 'longterm');
        }
        return $result;
    }
}

我想知道使用参数(别名)缓存查询是否有效,还是只缓存不带参数的查询更好?

$result = $this->find('all', array('order' =>'id'));

因为我的疑问是:缓存带参数的查询有用吗?是一种让网站速度更高效的好方法吗?

4

0 回答 0