V - data type to be returned by the cache.public class EmptyCacheProvider<V> extends AbstractCacheProvider<V>
CacheProvider interface
that implements the design pattern Empty Object.
It provides a caching system where all insertions will take no effect and the cache will always be empty.
This implementation can be useful for testing purposes and in those cases where your code is invoking the cache but you do not want to actually cache anything.
| Modifier | Constructor and Description |
|---|---|
protected |
EmptyCacheProvider()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
doClear()
Removes all keys and related entries from the cache.
|
CacheEntry<V> |
doGet(CacheKey key)
Returns the cache entry related to the given key.
|
void |
doPut(CacheKey key,
CacheEntry<V> entry,
long duration)
Binds the given entry to the given key and
put it into the underlying cache.
|
void |
doRemove(CacheKey key)
Removes the given key and the related entry from the cache.
|
boolean |
doTouch(CacheKey key,
long duration)
Defers the expiration time of the cache entry related to the given key.
|
static EmptyCacheProvider |
get()
Returns the singleton instance of the
EmptyCacheProvider. |
public static final Logger logger
By default the logging level is Level.WARNING and will only log exceptions.
If you want to log any caching operation you need to set the logging level to Level.FINE.
If you trust this class to work properly and you do not want your logs to get dirty
you can turn off this log by setting the logging level to Level.OFF.
To change the Logger levels and outputs follow the
Java documentation.
protected EmptyCacheProvider()
This constructor is intended to be used by extending classes only.
To get the singleton instance of the
EmptyCacheProvider use the factory method.
public static EmptyCacheProvider get()
EmptyCacheProvider.EmptyCacheProvider.public CacheEntry<V> doGet(CacheKey key)
If the given key was never being cached null
will be returned, otherwise will be returned a
CacheEntry containing the cached value
and the expiration time.
doGet in class AbstractCacheProvider<V>key - the cache key to search for.null otherwise.public void doPut(CacheKey key, CacheEntry<V> entry, long duration)
If the given key is already present into the cache will be replaced.
doPut in class AbstractCacheProvider<V>key - key to be cached.entry - entry to be cached.duration - number of milliseconds until expiration.public boolean doTouch(CacheKey key, long duration)
If no entry is present for the given key a RequirementFailure
should be thrown.
Only the first thread calling this method for the given key should be successful,
any other thread should fail. This method returns true if the operation
was successful and false otherwise.
doTouch in class AbstractCacheProvider<V>key - key to update.duration - number of milliseconds until expiration.true if the related entry has been updated.public void doRemove(CacheKey key)
If the key is not present nothing will be done.
doRemove in class AbstractCacheProvider<V>key - key to be removed.public void doClear()
If cache is already empty nothing will be done.
doClear in class AbstractCacheProvider<V>Copyright © 2011–2020 Nerd4j. All rights reserved.