de.innovationgate.utils.cache
public class Cache extends java.lang.Object
CacheFactory.createCache(String, int, Map)
.
This cache offers the following features:
This cache object uses different backend cache implementations ("cache cores") based on configuration.
Use sysproperty "de.innovationgate.utils.cache.core" to specify the implementation to use.
Cache implementations must use the interface CacheCore
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PARAM_DISPOSAL_LISTENER
Injects an
CacheDisposalListener implementation which will be notified about cache elements being removed/evicted |
static java.lang.String |
PARAM_EVICTION_POLICY
Control the eviction policy of the cache.
|
static java.lang.String |
PARAM_TIME_TO_LIVE_SECONDS
A java.lang.Integer that determines how long a cache entry may live in cache
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Callback function used, when the cache is no longer needed.
|
void |
flush(java.io.Serializable key)
Flushes a single entry of the cache
|
void |
flushAll()
Flushes the complete cache
|
void |
flushEntry(java.lang.String key)
Deprecated.
|
void |
flushGroup(java.lang.String group)
Flushes the entries of the cache that belong to the given group
|
CacheCore |
getCore() |
java.util.Set<java.io.Serializable> |
getEntryKeys()
Returns a set of the keys of the currently stored entries
May throw a CacheException if this is not supported by the cache implementation
|
long |
getMaxSize()
Returns the maximum number of entries allowed in the cache
|
long |
getSize()
Returns the current number of entries in the cache
|
int |
getUtilisation()
Returns a percent value, describing how many cache retrieval operations actually could return a cache value.
|
java.lang.Object |
read(java.io.Serializable key)
Reads a cache entry.
|
java.lang.Object |
readEntry(java.lang.String key)
Deprecated.
|
void |
write(java.io.Serializable key,
java.lang.Object obj)
Writes a cache entry
|
void |
write(java.io.Serializable key,
java.lang.Object obj,
java.lang.String group)
Writes a cache entry
|
void |
write(java.io.Serializable key,
java.lang.Object obj,
java.lang.String group,
int secondsToLive)
Writes a cache entry
|
void |
writeEntry(java.lang.String key,
java.lang.Object obj)
Deprecated.
|
void |
writeEntry(java.lang.String key,
java.lang.Object obj,
java.lang.String group)
Deprecated.
|
void |
writeEntry(java.lang.String key,
java.lang.Object obj,
java.lang.String group,
int secondsToLive)
Deprecated.
|
void |
writeEntryWithParams(java.lang.String key,
java.lang.Object obj,
CacheEntryParams params)
Deprecated.
|
void |
writeWithParams(java.io.Serializable key,
java.lang.Object obj,
CacheEntryParams params)
Writes a cache entry, being able to use all available entry params
|
public static final java.lang.String PARAM_TIME_TO_LIVE_SECONDS
public static final java.lang.String PARAM_DISPOSAL_LISTENER
CacheDisposalListener
implementation which will be notified about cache elements being removed/evictedpublic static final java.lang.String PARAM_EVICTION_POLICY
public void destroy() throws CacheException
CacheException
public void flushAll() throws CacheException
CacheException
public void flush(java.io.Serializable key) throws CacheException
key
- The cache keyCacheException
public void flushEntry(java.lang.String key) throws CacheException
flush(Serializable)
key
- The cache keyCacheException
public void flushGroup(java.lang.String group) throws CacheException
group
- The group to be flushedCacheException
public java.util.Set<java.io.Serializable> getEntryKeys() throws CacheException
CacheException
public long getMaxSize() throws CacheException
CacheException
public long getSize() throws CacheException
CacheException
public int getUtilisation() throws CacheException
CacheException
public java.lang.Object read(java.io.Serializable key) throws CacheException
key
- The key of the cache entryCacheException
public java.lang.Object readEntry(java.lang.String key) throws CacheException
read(Serializable)
key
- The key of the cache entryCacheException
public void write(java.io.Serializable key, java.lang.Object obj, java.lang.String group) throws CacheException
key
- The key of the entryobj
- The entry valuegroup
- An optional group for the entry. Specify null if no group desired.CacheException
public void writeEntry(java.lang.String key, java.lang.Object obj, java.lang.String group) throws CacheException
write(Serializable, Object, String)
key
- The key of the entryobj
- The entry valuegroup
- An optional group for the entry. Specify null if no group desired.CacheException
public void write(java.io.Serializable key, java.lang.Object obj, java.lang.String group, int secondsToLive) throws CacheException
key
- The key of the entryobj
- The entry valuegroup
- An optional group for the entry. Specify null if no group desired.secondsToLive
- Lateny of this cache entry in secondsCacheException
public void writeEntry(java.lang.String key, java.lang.Object obj, java.lang.String group, int secondsToLive) throws CacheException
write(Serializable, Object, String, int)
key
- The key of the entryobj
- The entry valuegroup
- An optional group for the entry. Specify null if no group desired.secondsToLive
- Lateny of this cache entry in secondsCacheException
public void writeWithParams(java.io.Serializable key, java.lang.Object obj, CacheEntryParams params) throws CacheException
key
- The key of the entryobj
- The entry valueparams
- Cache entry parametersCacheException
public void writeEntryWithParams(java.lang.String key, java.lang.Object obj, CacheEntryParams params) throws CacheException
writeWithParams(Serializable, Object, CacheEntryParams)
key
- The key of the entryobj
- The entry valueparams
- Cache entry parametersCacheException
public void write(java.io.Serializable key, java.lang.Object obj) throws CacheException
key
- The key of the entryobj
- The entry valueCacheException
public void writeEntry(java.lang.String key, java.lang.Object obj) throws CacheException
write(Serializable, Object)
key
- The key of the entryobj
- The entry valueCacheException
public CacheCore getCore()