/** * Clear all data from cache. */ public static void clear() { if (cacheImpl != null) { cacheImpl.clear(); } }
/** * Decrement the element value (must be a Number) by 1. * @param key Element key * @return The new value */ public static long decr(String key) { return cacheImpl.decr(key, 1); }
/** * Delete an element from the cache. * @param key The element key */ public static void delete(String key) { cacheImpl.delete(key); }
/** * Retrieve an object. * @param key The element key * @return The element value or null */ public static Object get(String key) { return cacheImpl.get(key); }
/** * Increment the element value (must be a Number). * @param key Element key * @param by The incr value * @return The new value */ public static long incr(String key, int by) { return cacheImpl.incr(key, by); }
/** * Add an element only if it doesn't exist and store it indefinitely. * @param key Element key * @param value Element value */ public static void add(String key, Object value) { checkSerializable(value); cacheImpl.add(key, value, Time.parseDuration(null)); }
/** * Replace an element only if it already exists. * @param key Element key * @param value Element value * @param expiration Ex: 10s, 3mn, 8h */ public static void replace(String key, Object value, String expiration) { checkSerializable(value); cacheImpl.replace(key, value, Time.parseDuration(expiration)); }
/** * Delete an element from the cache and return only when the * element is effectively removed. * @param key The element key * @return If the element an eventually been deleted */ public static boolean safeDelete(String key) { return cacheImpl.safeDelete(key); }
/** * Add an element only if it doesn't exist, and return only when * the element is effectively cached. * @param key Element key * @param value Element value * @param expiration Ex: 10s, 3mn, 8h * @return If the element an eventually been cached */ public static boolean safeAdd(String key, Object value, String expiration) { checkSerializable(value); return cacheImpl.safeAdd(key, value, Time.parseDuration(expiration)); }
/** * Replace an element only if it already exists and return only when the * element is effectively cached. * @param key Element key * @param value Element value * @param expiration Ex: 10s, 3mn, 8h * @return If the element an eventually been cached */ public static boolean safeReplace(String key, Object value, String expiration) { checkSerializable(value); return cacheImpl.safeReplace(key, value, Time.parseDuration(expiration)); }
/** * Bulk retrieve. * @param key List of keys * @return Map of keys & values */ public static Map<String, Object> get(String... key) { return cacheImpl.get(key); }
/** * Increment the element value (must be a Number) by 1. * @param key Element key * @return The new value */ public static long incr(String key) { return cacheImpl.incr(key, 1); }
/** * Add an element only if it doesn't exist. * @param key Element key * @param value Element value * @param expiration Ex: 10s, 3mn, 8h */ public static void add(String key, Object value, String expiration) { checkSerializable(value); cacheImpl.add(key, value, Time.parseDuration(expiration)); }
/** * Replace an element only if it already exists and store it indefinitely. * @param key Element key * @param value Element value */ public static void replace(String key, Object value) { checkSerializable(value); cacheImpl.replace(key, value, Time.parseDuration(null)); }
/** * Convenient clazz to get a value a class type; * @param <T> The needed type * @param key The element key * @param clazz The type class * @return The element value or null */ @SuppressWarnings("unchecked") public static <T> T get(String key, Class<T> clazz) { return (T) cacheImpl.get(key); }
/** * Decrement the element value (must be a Number). * @param key Element key * @param by The decr value * @return The new value */ public static long decr(String key, int by) { return cacheImpl.decr(key, by); }