public abstract class Cache extends Object
Modifier and Type | Field and Description |
---|---|
static CacheImpl |
cacheImpl
The underlying cache implementation
|
static CacheImpl |
forcedCacheImpl
Sometime we REALLY need to change the implementation :)
|
Constructor and Description |
---|
Cache() |
Modifier and Type | Method and Description |
---|---|
static void |
add(String key,
Object value)
Add an element only if it doesn't exist and store it indefinitely.
|
static void |
add(String key,
Object value,
String expiration)
Add an element only if it doesn't exist.
|
static void |
clear()
Clear all data from cache.
|
static long |
decr(String key)
Decrement the element value (must be a Number) by 1.
|
static long |
decr(String key,
int by)
Decrement the element value (must be a Number).
|
static void |
delete(String key)
Delete an element from the cache.
|
static Map<String,Object> |
get(String... key)
Bulk retrieve.
|
static Object |
get(String key)
Retrieve an object.
|
static <T> T |
get(String key,
Class<T> clazz)
Convenient clazz to get a value a class type;
|
static long |
incr(String key)
Increment the element value (must be a Number) by 1.
|
static long |
incr(String key,
int by)
Increment the element value (must be a Number).
|
static void |
init()
Initialize the cache system.
|
static void |
replace(String key,
Object value)
Replace an element only if it already exists and store it indefinitely.
|
static void |
replace(String key,
Object value,
String expiration)
Replace an element only if it already exists.
|
static boolean |
safeAdd(String key,
Object value,
String expiration)
Add an element only if it doesn't exist, and return only when
the element is effectively cached.
|
static boolean |
safeDelete(String key)
Delete an element from the cache and return only when the
element is effectively removed.
|
static boolean |
safeReplace(String key,
Object value,
String expiration)
Replace an element only if it already exists and return only when the
element is effectively cached.
|
static boolean |
safeSet(String key,
Object value,
String expiration)
Set an element and return only when the element is effectively cached.
|
static void |
set(String key,
Object value)
Set an element and store it indefinitely.
|
static void |
set(String key,
Object value,
String expiration)
Set an element.
|
static void |
stop()
Stop the cache system.
|
public static CacheImpl cacheImpl
public static CacheImpl forcedCacheImpl
public static void add(String key, Object value, String expiration)
key
- Element keyvalue
- Element valueexpiration
- Ex: 10s, 3mn, 8hpublic static boolean safeAdd(String key, Object value, String expiration)
key
- Element keyvalue
- Element valueexpiration
- Ex: 10s, 3mn, 8hpublic static void add(String key, Object value)
key
- Element keyvalue
- Element valuepublic static void set(String key, Object value, String expiration)
key
- Element keyvalue
- Element valueexpiration
- Ex: 10s, 3mn, 8hpublic static boolean safeSet(String key, Object value, String expiration)
key
- Element keyvalue
- Element valueexpiration
- Ex: 10s, 3mn, 8hpublic static void set(String key, Object value)
key
- Element keyvalue
- Element valuepublic static void replace(String key, Object value, String expiration)
key
- Element keyvalue
- Element valueexpiration
- Ex: 10s, 3mn, 8hpublic static boolean safeReplace(String key, Object value, String expiration)
key
- Element keyvalue
- Element valueexpiration
- Ex: 10s, 3mn, 8hpublic static void replace(String key, Object value)
key
- Element keyvalue
- Element valuepublic static long incr(String key, int by)
key
- Element keyby
- The incr valuepublic static long incr(String key)
key
- Element keypublic static long decr(String key, int by)
key
- Element keyby
- The decr valuepublic static long decr(String key)
key
- Element keypublic static Object get(String key)
key
- The element keypublic static Map<String,Object> get(String... key)
key
- List of keyspublic static void delete(String key)
key
- The element keypublic static boolean safeDelete(String key)
key
- The element keypublic static void clear()
public static <T> T get(String key, Class<T> clazz)
T
- The needed typekey
- The element keyclazz
- The type classpublic static void init()
public static void stop()
Guillaume Bort & zenexity - Distributed under Apache 2 licence, without any warrantly