Updated on 2023-11-17 GMT+08:00

CacheUtils

Path

com.huawei.livedata.lambdaservice.util.CacheUtils

Description

This class is used to save and obtain cache information.

Example

Before using CacheUtils, create an object first.

The get method of CacheUtils allows only the following items in the whitelist to be used as a key:

"DICT:api_gw_rest_addr", "DICT:api_gw_rest_float_addr", "DICT:api_gw_rest_eip_addr", "DICT:livedata_private_address"

Example:

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

The returned result is the private IP address of LiveData.

Example of putCache and getCache methods:

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
}

The returned result is 20.

Method List

Returned Type

Method and Description

static boolean

putCache(String key, String value)

Save cache information.

static boolean

putCache(String key, String value, int time)

Save the cache information with the timeout interval.

static String

getCache(String key)

Obtain cache information.

static long

removeCache(String key)

Remove cache information.

static String

get(String key)

Obtain dictionary cache information.

Method Details

  • public static boolean putCache(String key, String value)

    Save cache information.

    Input Parameter

    • key indicates the key value of cache information.
    • value indicates the cache information.

    Returns

    Corresponding boolean value.

  • public static boolean putCache(String key, String value, int time)

    Save the cache information with the timeout interval.

    Input Parameter

    • key indicates the key value of cache information.
    • value indicates the cache information.
    • time indicates the timeout duration, in seconds. Cache information will be deleted after the timeout. Querying this information will return a null value.

    Returns

    Corresponding boolean value.

  • public static String getCache(String key)

    Obtain cache information.

    Input Parameter

    key indicates the key value of cache information.

    Returns

    Cache information corresponding to the key value.

  • public static long removeCache(String key)

    Remove cache information.

    Input Parameter

    key indicates the key value of cache information to be removed.

    Returns

    Execution result.

  • public static String get(String key)

    Obtain dictionary cache information.

    Input Parameter

    key indicates the key value of dictionary cache information.

    Returns

    Dictionary cache information corresponding to the key value.