public class InteralCacheService extends Object implements CacheService
CacheService.StateDEF_CACHE_NAME| Constructor and Description |
|---|
InteralCacheService() |
| 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
|
CacheService.State |
state()
Return state of this cache service.
|
public void put(String key, Object value, int ttl)
CacheServiceStore an item into the cache service by key and set ttl value
put in interface CacheServicekey - 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 usedpublic void put(String key, Object value)
CacheServiceStore an item into the cache by key and use default ttl
put in interface CacheServicekey - the cache keyvalue - the object to be cachedpublic void evict(String key)
CacheServiceRemove an item from the cache service by key
evict in interface CacheServicekey - the cache keypublic <T> T get(String key)
CacheServiceReturn an item from the cache service by key
get in interface CacheServiceT - the generic type of the return valuekey - the cache keypublic int incr(String key)
CacheServiceIncrease 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.
incr in interface CacheServicekey - the key index the numeric valuepublic int incr(String key, int ttl)
CacheServiceIncrease 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.
incr in interface CacheServicekey - the key index the numeric valuettl - the number of seconds the key to expirepublic int decr(String key)
CacheServiceDecrease 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.
decr in interface CacheServicekey - the key index the numeric valuepublic int decr(String key, int ttl)
CacheServiceDecrease 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.
decr in interface CacheServicekey - the key index the numeric valuettl - the number of seconds the key to expirepublic void clear()
CacheServiceRemove all cached items
clear in interface CacheServicepublic void setDefaultTTL(int ttl)
CacheServiceSet 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
setDefaultTTL in interface CacheServicettl - the default ttl value in secondspublic void shutdown()
CacheServiceShutdown the cache service
shutdown in interface CacheServicepublic void startup()
CacheServiceRestart the cache service after shutdown
Note, by default the cache service should be started after initialized
startup in interface CacheServicepublic CacheService.State state()
CacheServiceReturn state of this cache service.
state in interface CacheServiceCacheService.State of this cache service.Copyright © 2014–2021 OSGL (Open Source General Library). All rights reserved.