Fx.cache

Fx.cache: function cache

1. DefaultCache

Fx.cache.getDefaultCache()

return type

Cache

Java example

Cache cache = Fx.cache.getDefaultCache();
log.info(cache.get("key1"));
cache.put("key1", 1234, 5);
log.info(cache.contains("key1"));
int value = (Integer) cache. get("key1");
log. info(value);
log.info(cache.inc("key1"));
if (cache. remove("key1")) {
    log.info("remove success!");
}
log.info(cache.get("key1"));

Groovy example

Cache cache = Fx.cache.getDefaultCache()
log.info(cache.get("key1"))
cache. put("key1", 1234, 5)
log.info(cache.contains("key1"))
Integer value = (Integer) cache. get("key1")
log. info(value)
log.info(cache.inc("key1"))
if(cache. remove("key1")) {
  log.info("remove success!")
}
log.info(cache.get("key1"))

(1). Reference Cache
Precautions

  • limit
    The maximum length of the key string is 256
    The maximum length of the value string is 1M
    The maximum failure time is 48h

Reference class com.fxiaoke.functions.interfaces.Cache

1. Whether the cache key exists

contains(<java.lang.String key>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | Keyword maximum length 256 |

return type

boolean

2. Insert key-value pairs

put(<java.lang.String key>, <java.lang.String value>, <java.lang.Integer ttlSecs>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | Keyword maximum length 256 bytes |
| value | String | The maximum length of the string is 1M |
| ttlSecs | Integer | Expiration time unit: second (valid from 1 to 172800) |

return type

void

3. It is not recommended to use the key to get the value. If the key does not exist, return null, and the returned result is Object. You need to convert the type as String / as Integer according to your needs.

get(<java.lang.String key>)

Parameter Description

| parameter | type| Description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | Keyword maximum length 256 bytes |

return type

java.lang.Object

4. Get the value through the key, and the return result type is String

getString(<java.lang.String key>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | Keyword maximum length 256 bytes |

return type

java.lang.String

5. Get the value through the key, and the return result type is Integer

getInteger(<java.lang.String key>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | Keyword maximum length 256 bytes |

return type

java.lang.Integer

6. Get the value through the key, and the return result type is Long

getLong(<java.lang.String key>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | Keyword maximum length 256 bytes |

return type

java.lang.Long

7. Delete cache

remove(<java.lang.String key>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | Keyword maximum length 256 bytes |

return type

java.lang.Boolean

8. Add one to the digital key (value is not supported for strings)

inc(<java.lang.String key>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | -------------------------------------- ---------------------- |
| key | String | Keyword maximum length 256 bytes |

return type

java.lang.Long

9. Subtract one from the digital key (value is not supported for strings)

dec(<java.lang.String key>)

Parameter Description

| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| key | String | Keyword maximum length 256 bytes |

return type

java.lang.Long

2022-11-23
0 0