public class InteralCacheService extends Object implements CacheService
DEF_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
|
public void put(String key, Object value, int ttl)
CacheService
Store an item into the cache service by key and set ttl value
put
in interface CacheService
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 usedpublic void put(String key, Object value)
CacheService
Store an item into the cache by key and use default ttl
put
in interface CacheService
key
- the cache keyvalue
- the object to be cachedpublic void evict(String key)
CacheService
Remove an item from the cache service by key
evict
in interface CacheService
key
- the cache keypublic <T> T get(String key)
CacheService
Return an item from the cache service by key
get
in interface CacheService
T
- the generic type of the return valuekey
- the cache keypublic int incr(String key)
CacheService
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
.
incr
in interface CacheService
key
- the key index the numeric valuepublic int incr(String key, int ttl)
CacheService
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
.
incr
in interface CacheService
key
- the key index the numeric valuettl
- the number of seconds the key to expirepublic int decr(String key)
CacheService
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
.
decr
in interface CacheService
key
- the key index the numeric valuepublic int decr(String key, int ttl)
CacheService
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
.
decr
in interface CacheService
key
- the key index the numeric valuettl
- the number of seconds the key to expirepublic void clear()
CacheService
Remove all cached items
clear
in interface CacheService
public void setDefaultTTL(int ttl)
CacheService
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
setDefaultTTL
in interface CacheService
ttl
- the default ttl value in secondspublic void shutdown()
CacheService
Shutdown the cache service
shutdown
in interface CacheService
public void startup()
CacheService
Restart the cache service after shutdown
Note, by default the cache service should be started after initialized
startup
in interface CacheService
Copyright © 2014–2018 OSGL (Open Source General Library). All rights reserved.