\PhalApi_ModelProxy

Model Proxy Class, Solution To Deal With Heaviy Data

  • cache heaviy data to save expensive cost
  • in order to pass required params, we introduce Value Object, i.e. PhalApi_ModelQuery query object
  • sub-class have to implement how to get source data, returning the unique cache key, and expire time
  • use this proxy only when you need


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);

Summary

Methods
Properties
Constants
__construct()
getData()
No public properties found
No constants found
doGetData()
getKey()
getExpire()
$cache
N/A
No private methods found
No private properties found
N/A

Properties

$cache

$cache : 

Type

Methods

__construct()

__construct(\PhalApi_Cache  $cache = NULL) 

Parameters

\PhalApi_Cache $cache

specify cache service for the proxy, default is: DI()->cache

getData()

getData(\PhalApi_ModelQuery  $query = NULL) : mixed

Template Method: Get the source data

Parameters

\PhalApi_ModelQuery $query

query object

Returns

mixed —

source data, DO NOT return NULL when fail, otherwise still try to get source data again and again

doGetData()

doGetData(\PhalApi_ModelQuery  $query) : mixed

Implementation: Get source data

Parameters

\PhalApi_ModelQuery $query

query object

Returns

mixed

getKey()

getKey(\PhalApi_ModelQuery  $query) : String

Implementation: Return unique cache key

Parameters

\PhalApi_ModelQuery $query

query object

Returns

String

getExpire()

getExpire(\PhalApi_ModelQuery  $query) : Int

Implementation: Reture expire time

Parameters

\PhalApi_ModelQuery $query

query object

Returns

Int —

unit: second