public interface CacheService
Defines a cache service
Modifier and Type | Field and Description |
---|---|
static String |
DEF_CACHE_NAME |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Remove all cached items
|
int |
decr(String key)
Decrease an number type value associated with key
key by 1 |
int |
decr(String key,
int ttl)
Decrease an number type value associated with key
key by 1 with expires specified |
void |
evict(String key)
Remove an item from the cache service by key
|
<T> T |
get(String key)
Return an item from the cache service by key
|
int |
incr(String key)
Increase an number type value associated with key
key by 1 |
int |
incr(String key,
int ttl)
Increase an number type value associated with key
key with expires specified |
void |
put(String key,
Object value)
Store an item into the cache by key and use default ttl
|
void |
put(String key,
Object value,
int ttl)
Store an item into the cache service by key and set ttl value
|
void |
setDefaultTTL(int ttl)
Set default ttl value which will be used if user pass 0 as ttl or not specified ttl Note some service might not favor this method after the internal cache service is initialized.
|
void |
shutdown()
Shutdown the cache service
|
void |
startup()
Restart the cache service after shutdown
|
static final String DEF_CACHE_NAME
void put(String key, Object value, int ttl)
Store an item into the cache service by key and set ttl value
key
- the cache keyvalue
- the object to be cachedttl
- time to live of the cached item. Time unit is second. If set to negative number, then it will never expire. If set to zero then the default ttl value will be usedvoid put(String key, Object value)
Store an item into the cache by key and use default ttl
key
- the cache keyvalue
- the object to be cachedvoid evict(String key)
Remove an item from the cache service by key
key
- the cache key<T> T get(String key)
Return an item from the cache service by key
T
- the generic type of the return valuekey
- the cache keyint incr(String key)
Increase an number type value associated with key key
by 1
If no value is associated with the key, then it will associate number 1
to key
and return 0
.
key
- the key index the numeric valueint incr(String key, int ttl)
Increase an number type value associated with key key
with expires specified
If no value is associated with the key, then it will associate number 1
to key
and return 0
.
key
- the key index the numeric valuettl
- the number of seconds the key to expireint decr(String key)
Decrease an number type value associated with key key
by 1
If no value is associated with the key, then it will associate number -1
to key
and return 0
.
key
- the key index the numeric valueint decr(String key, int ttl)
Decrease an number type value associated with key key
by 1
with expires specified
If no value is associated with the key, then it will associate number -1
to key
and return 0
.
key
- the key index the numeric valuettl
- the number of seconds the key to expirevoid clear()
Remove all cached items
void setDefaultTTL(int ttl)
Set default ttl value which will be used if user pass 0 as ttl or not specified ttl Note some service might not favor this method after the internal cache service is initialized. E.g. memcached and ehcaches
ttl
- the default ttl value in secondsvoid shutdown()
Shutdown the cache service
void startup()
Restart the cache service after shutdown
Note, by default the cache service should be started after initialized
Copyright © 2014–2018 OSGL (Open Source General Library). All rights reserved.