$cache
$cache :
PhalApi_ModelProxy 模型Model代理 - 重量级数据获取的应对方案
实例和使用示例:
class ModelProxy_UserBaseInfo extends PhalApi_ModelProxy {
protected function doGetData($query) {
$model = new Model_User();
return $model->getByUserId($query->id);
}
protected function getKey($query) {
return 'userbaseinfo_' . $query->id;
}
protected function getExpire($query) {
return 600;
}
}
//最终的调用
$query = new PhalApi_ModelQuery();
$query->id = $userId;
$modelProxy = new ModelProxy_UserBaseInfo();
$rs = $modelProxy->getData($query);
__construct(\PhalApi_Cache $cache = NULL)
为代理指定委托的缓存组件,默认情况下使用DI()->cache
\PhalApi_Cache | $cache |
getData(\PhalApi_ModelQuery $query = NULL) : mixed
获取源数据 - 模板方法
\PhalApi_ModelQuery | $query | 查询对象 |
返回源数据,但在失败的情况下别返回NULL,否则依然会穿透到此