StartMVC开发手册

可以快速上手的开发文档

手册目录

数据缓存

数据缓存cache

cache($timeoute),

参数为缓存时间,默认是3600秒, 修改默认缓存时间和缓存目录,可以数据库配置中修改/config/database.php

'cachetime' => 3600,//缓存时间(秒)
'cachedir'	=> ROOT_PATH . 'runtime'.DS.'db'.DS,//缓存目录(可选)
// 使用默认缓存时间(从配置文件获取)
$result = Db::table('users')
    ->where('status', 1)
    ->cache()
    ->get();

// 指定缓存时间为300秒(5分钟)
$result = Db::table('articles')
    ->where('published', 1)
    ->cache(300)
    ->get();

// 长期缓存(24小时)
$result = Db::table('categories')
    ->orderBy('sort', 'ASC')
    ->cache(86400)
    ->getAll();
  • cache(30)