应用与数据集成平台 ROMA Connect-CacheUtils类说明:使用示例

时间:2025-02-12 14:55:43

使用示例

在使用CacheUtils之前,需要new一个新对象方可调用。

CacheUtils的get方法只允许使用白名单里的几项作为键:

"DICT:api_gw_rest_addr"、"DICT:api_gw_rest_float_addr"、"DICT:api_gw_rest_eip_addr"、"DICT:livedata_private_address"

示例:

importClass(com.huawei.livedata.lambdaservice.util.CacheUtils);function execute(data) {  var cacheUtils = new CacheUtils  var value = cacheUtils.get("DICT:livedata_private_address")  return value}

返回的结果为livedata的内网地址。

putCache方法和getCache方法可以实现缓存的使用示例:

importClass(com.huawei.livedata.lambdaservice.util.CacheUtils);function execute(data) {  var cacheUtils = new CacheUtils  code = cacheUtils.putCache("age", "20")  if (code != true) {    return code  }  var name = cacheUtils.getCache("age")  return name}

返回的结果为20。

support.huaweicloud.com/devg-roma/apic-dev-190603056.html