$cache
$cache :
Model Proxy Class, Solution To Deal With Heaviy Data
PhalApi_ModelQuery
query object
Implementation and usage:
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;
}
}
// final call
$query = new PhalApi_ModelQuery();
$query->id = $userId;
$modelProxy = new ModelProxy_UserBaseInfo();
$rs = $modelProxy->getData($query);
__construct(\PhalApi_Cache $cache = NULL)
\PhalApi_Cache | $cache | specify cache service for the proxy, default is: DI()->cache |
getData(\PhalApi_ModelQuery $query = NULL) : mixed
Template Method: Get the source data
\PhalApi_ModelQuery | $query | query object |
source data, DO NOT return NULL when fail, otherwise still try to get source data again and again
doGetData(\PhalApi_ModelQuery $query) : mixed
Implementation: Get source data
\PhalApi_ModelQuery | $query | query object |
getKey(\PhalApi_ModelQuery $query) : String
Implementation: Return unique cache key
\PhalApi_ModelQuery | $query | query object |
getExpire(\PhalApi_ModelQuery $query) : Int
Implementation: Reture expire time
\PhalApi_ModelQuery | $query | query object |
unit: second