缓存
CmlPHP在model层做了缓存集成(实时的,一量有数据变更会自动更新缓存)。一般情况下开发人员无需关注缓存问题。对于高并发的场景如:门户/资讯类的页面,对实时性要求不高,但是并发又很高的情况。如果还是实时更新缓存的话容易出现缓存雪奔的情况。这个时候开发人员可根据实际业务需要单独加缓存。使用方法如下:
//某控制器中
$articleType1 = Model::getInstance()->cache()->get('article:type:1');
if (!$articleType1) {
//从model中取
$articleType1 = 111;
//设置10分钟缓存
Model::getInstance()->cache()->set('article:type:1', $articleType1, 600);
}
//某Model中
$articleType1 = $this->cache()->get('article:type:1');
if (!$articleType1) {
//从model中取
$articleType1 = 111;
//设置10分钟缓存
$this->cache()->set('article:type:1', $articleType1, 600);
}
return $articleType1;