/** * @brief Dao层CacheProxy的具体处理逻辑 * * @param $func 用户传入的函数名 * @param $args 传递给$func函数的参数 * @return 从cache中拿到的数据或者是$func调用拿到的数据 * @retval 同$func对应函数返回数据类型一致 * @author chenyijie * @date 2012/09/27 20:32:42 **/ public function __call($func, $args) { if (!parent::_isCacheOpen('daocache/Global/cache')) { //不用cache 则直接调用类指定的方法 return parent::_getFunctionCall($func, $args); } return true; }
/** * @brief DataService层CacheProxy的具体处理逻辑 * * @param $func 用户传入的函数名 * @param $args 传递给$func函数的参数 * @return 从cache中拿到的数据或者是$func调用拿到的数据 * @retval 同$func对应函数返回数据类型一致 * @author chenyijie * @date 2012/09/27 20:32:42 **/ public function __call($func, $args) { $this->cacheKeyConfPath = 'dscache/funcToKey/' . $this->objClassName . '/' . $func; $result = parent::_init('dscache', $func, $args); if ($this->initState === false) { //CacheProxyAbstract::_init()方法中如果有return的情况 则把return的值传递到上层 return $result; } //Key的生成规则:APP名(或者用户指定)_配置文件中指定key_参数值 $key = $this->firstKeySection . $this->linkSign; $key = $key . $this->cacheKeyFromConf['key'] . $this->linkSign; $callable = method_exists($this->objClass, 'getKey'); if ($callable === true) { $key = $key . strval($this->objClass->getKey($func, $args)); } else { $key = $key . $args[0]; } $arrErr = array('caller' => 'DsCacheProxy', 'class' => get_class($this->objClass), 'function' => $func, 'key' => $key); if ($this->cacheKeyFromConf['type'] === 'get') { $value = $this->objCacheClient->get($key); if ($value === false) { Bd_Log::trace("Get data from cache failed, call user func to get data from Database", parent::GET_DATA_FAILED, $arrErr); $value = parent::_getFunctionCall($func, $args); $cacheKeyDisableTime = parent::_getKeyDisableTime('dscache/Global/KeyDisableTime'); $this->objCacheClient->add($key, $value, $cacheKeyDisableTime); //add操作失败则不进行任何操作 } Bd_Log::trace("Get data from cache success.", 0, $arrErr); return $value; } else { if ($this->cacheKeyFromConf['type'] === 'set') { $value = parent::_getFunctionCall($func, $args); $cacheKeyDisableTime = parent::_getKeyDisableTime('dscache/Global/KeyDisableTime'); $state = $this->objCacheClient->delete($key); if ($state === false) { Bd_Log::trace("Delete data in cache failed.", parent::DELETE_DATA_FAILED, $arrErr); return false; } $this->objCacheClient->add($key, $value, $cacheKeyDisableTime); //add操作失败则不进行任何操作 Bd_Log::trace("Set data in cache success.", 0, $arrErr); return true; } else { $value = parent::_getFunctionCall($func, $args); Bd_Log::warning('Get config failed, can not get correct function cache operation type.', parent::GET_CONF_FAILED, $arrErr); return $value; } } }