Package ninja.cache
Class CacheEhCacheImpl
- java.lang.Object
-
- ninja.cache.CacheEhCacheImpl
-
- All Implemented Interfaces:
Cache
public class CacheEhCacheImpl extends Object implements Cache
EhCache implementation.Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.
See https://www.ehcache.org/ expiration is specified in seconds Heavily inspired by excellent Play! 1.2.5 implementation.
-
-
Constructor Summary
Constructors Constructor Description CacheEhCacheImpl(org.slf4j.Logger logger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(String key, Object value, int expiration)
Add object to cache.void
clear()
Clear all values in cache.long
decr(String key, int by)
Decrements key by value.void
delete(String key)
Delete key from cache.Object
get(String key)
Returns the object for this key or null if not found.Map<String,Object>
get(String[] keys)
Returns all objects for the keys.long
incr(String key, int by)
Increments key by value.void
replace(String key, Object value, int expiration)
Replaces key with new value.boolean
safeAdd(String key, Object value, int expiration)
Similar todelete
method.boolean
safeDelete(String key)
Similar todelete
method.boolean
safeReplace(String key, Object value, int expiration)
Similar todelete
method.boolean
safeSet(String key, Object value, int expiration)
Similar todelete
method.void
set(String key, Object value, int expiration)
Adds object of cache.void
stop()
-
-
-
Method Detail
-
add
public void add(String key, Object value, int expiration)
Description copied from interface:Cache
Add object to cache. Important: If the key exists already it won't be overwritten. Use set(...) instead. This method is fire and forget. Implementations may implement this async and non-blocking.
-
clear
public void clear()
Description copied from interface:Cache
Clear all values in cache.
-
decr
public long decr(String key, int by)
Description copied from interface:Cache
Decrements key by value.
-
delete
public void delete(String key)
Description copied from interface:Cache
Delete key from cache.
-
get
public Object get(String key)
Description copied from interface:Cache
Returns the object for this key or null if not found.
-
get
public Map<String,Object> get(String[] keys)
Description copied from interface:Cache
Returns all objects for the keys.
-
incr
public long incr(String key, int by)
Description copied from interface:Cache
Increments key by value.
-
replace
public void replace(String key, Object value, int expiration)
Description copied from interface:Cache
Replaces key with new value. Important: Will do nothing if the key does not exist. This method is fire and forget. Implementations may implement this async and non-blocking.
-
safeAdd
public boolean safeAdd(String key, Object value, int expiration)
Description copied from interface:Cache
Similar todelete
method. BUT it blocks until execution succeeds / fails AND wraps exceptions in a simple true / false return value
-
safeDelete
public boolean safeDelete(String key)
Description copied from interface:Cache
Similar todelete
method. BUT it blocks until execution succeeds / fails AND wraps exceptions in a simple true / false return value- Specified by:
safeDelete
in interfaceCache
- Parameters:
key
- The key to delete- Returns:
- true if deletion was successful, false if not.
-
safeReplace
public boolean safeReplace(String key, Object value, int expiration)
Description copied from interface:Cache
Similar todelete
method. BUT it blocks until execution succeeds / fails AND wraps exceptions in a simple true / false return value- Specified by:
safeReplace
in interfaceCache
- Parameters:
key
- The key of the object to use for caching.value
- The value of the object to replace in the cache.expiration
- Expiration time in seconds.- Returns:
- true if replace was successful, false if not.
-
safeSet
public boolean safeSet(String key, Object value, int expiration)
Description copied from interface:Cache
Similar todelete
method. BUT it blocks until execution succeeds / fails AND wraps exceptions in a simple true / false return value
-
set
public void set(String key, Object value, int expiration)
Description copied from interface:Cache
Adds object of cache. Important: This method potentially overwrites previously existing object with new values. This method is fire and forget. Implementations may implement this async and non-blocking.
-
stop
public void stop()
-
-