public class CacheEhCacheImpl extends Object implements Cache
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.
expiration is specified in seconds
Heavily inspired by excellent Play! 1.2.5 implementation.
Constructor and Description |
---|
CacheEhCacheImpl(org.slf4j.Logger logger) |
Modifier and Type | Method and 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 to
delete method. |
boolean |
safeDelete(String key)
Similar to
delete method. |
boolean |
safeReplace(String key,
Object value,
int expiration)
Similar to
delete method. |
boolean |
safeSet(String key,
Object value,
int expiration)
Similar to
delete method. |
void |
set(String key,
Object value,
int expiration)
Adds object of cache.
|
void |
stop() |
public void add(String key, Object value, int expiration)
Cache
public void clear()
Cache
public long decr(String key, int by)
Cache
public void delete(String key)
Cache
public Object get(String key)
Cache
public Map<String,Object> get(String[] keys)
Cache
public long incr(String key, int by)
Cache
public void replace(String key, Object value, int expiration)
Cache
public boolean safeAdd(String key, Object value, int expiration)
Cache
delete
method.
BUT it blocks until execution succeeds / fails AND wraps
exceptions in a simple true / false return valuepublic boolean safeDelete(String key)
Cache
delete
method.
BUT it blocks until execution succeeds / fails AND wraps
exceptions in a simple true / false return valuesafeDelete
in interface Cache
key
- The key to deletepublic boolean safeReplace(String key, Object value, int expiration)
Cache
delete
method.
BUT it blocks until execution succeeds / fails AND wraps
exceptions in a simple true / false return valuesafeReplace
in interface Cache
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.public boolean safeSet(String key, Object value, int expiration)
Cache
delete
method.
BUT it blocks until execution succeeds / fails AND wraps
exceptions in a simple true / false return valuepublic void set(String key, Object value, int expiration)
Cache
public void stop()
Copyright © 2019 ninjaframework. All rights reserved.