通过KEY值清除缓存,可以设置缓存类型,暂时支持FLIE MYSQL MEM。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $key | String | 是 | 缓存键值 |
| $type | String | 否 | 缓存类型,值: FLIE MYSQL MEM |
class testaDao extends Dao {
public $db = 'test';
public function test() {
$this->dao->cache->set('test', 'woshishen', 0, 'FILE'); //设置缓存
$test = $this->dao->cache->get('test', 'FILE'); //获取缓存
$this->dao->cache->clear('test', 'FILE'); //清除单个缓存
$this->dao->cache->clear_all('FILE'); //清除全部缓存
}
}
通过缓存类型清除缓存。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $type | String | 否 | 缓存类型,值: FLIE MYSQL MEM |
class testaDao extends Dao {
public $db = 'test';
public function test() {
$this->dao->cache->set('test', 'woshishen', 0, 'FILE'); //设置缓存
$test = $this->dao->cache->get('test', 'FILE'); //获取缓存
$this->dao->cache->clear('test', 'FILE'); //清除单个缓存
$this->dao->cache->clear_all('FILE'); //清除全部缓存
}
}
通过KEY值获取缓存,可以设置缓存类型,暂时支持FLIE MYSQL MEM。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $key | String | 是 | 缓存键值 |
| $type | String | 否 | 缓存类型,值: FLIE MYSQL MEM |
class testaDao extends Dao {
public $db = 'test';
public function test() {
$this->dao->cache->set('test', 'woshishen', 0, 'FILE'); //设置缓存
$test = $this->dao->cache->get('test', 'FILE'); //获取缓存
$this->dao->cache->clear('test', 'FILE'); //清除单个缓存
$this->dao->cache->clear_all('FILE'); //清除全部缓存
}
}
获取缓存对象后,就可以直接调用缓存类里面的函数。例如:Memcache中的decrement就可以直接使用。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $type | String | 否 | 缓存类型,值: FLIE MYSQL MEM |
class testaDao extends Dao {
public $db = 'test';
public function test() {
$this->dao->cache->get_cache($type = 'MEM')->decrement('num', -1); //自动减一
}
}
该函数一般在Controller中使用,主要是用来做页面缓存用途。比如页面访问压力比较大,内容动态更新变化比较下,可以直接把整个页面存在内存中或者文件缓存中。
class indexController extends Controller {
public $initphp_list = array('test'); //Action白名单
public function run() {
$this->getCache()->page_cache_start("hello", 5, "MEM");
$this->view->set_tpl('index_run');
$this->view->display();
$this->getCache()->page_cache_end();
}
public function test() {}
}
该函数一般在Controller中使用,主要是用来做页面缓存用途。比如页面访问压力比较大,内容动态更新变化比较下,可以直接把整个页面存在内存中或者文件缓存中。
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $key | String | 是 | 缓存键值 |
| $time | Int | 否 | 缓存时间,0-永久缓存 |
| $type | String | 否 | 缓存类型,值: FLIE MYSQL MEM |
class indexController extends Controller {
public $initphp_list = array('test'); //Action白名单
public function run() {
$this->getCache()->page_cache_start("hello", 5, "MEM");
$this->view->set_tpl('index_run');
$this->view->display();
$this->getCache()->page_cache_end();
}
public function test() {}
}
可以设置缓存KEY值和VALUE值。time缓存时间,0-永久缓存。type = 'FILE'缓存类型设置,暂时支持FLIE MYSQL MEM。在Dao中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $key | String | 是 | 缓存键值 |
| $value | String | 是 | 缓存值 |
| $time | Int | 否 | 缓存时间,0-永久缓存 |
| $type | String | 否 | 缓存类型,值: FLIE MYSQL MEM |
class testaDao extends Dao {
public $db = 'test';
public function test() {
$this->dao->cache->set('test', 'woshishen', 0, 'FILE'); //设置缓存
$test = $this->dao->cache->get('test', 'FILE'); //获取缓存
$this->dao->cache->clear('test', 'FILE'); //清除单个缓存
$this->dao->cache->clear_all('FILE'); //清除全部缓存
}
}