public class InProcessMemoryCache extends Object implements Cache
ConcurrentHashMap
instances.
Note that this implementation does not check for overall heap consumption nor free system memory. Make sure you set the maximum size appropriate for your system!
Constructor and Description |
---|
InProcessMemoryCache()
Construction of 1mb cache.
|
InProcessMemoryCache(long maxSize)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
CacheEntry |
fetch(String key)
Fetches an entry from the cache if it's there and has not yet expired.
|
long |
getMaxSize()
The current max cache size.
|
long |
getSize()
The current cache size.
|
void |
invalidate(String tag)
Makes sure that all tagged entries are un-fetchable.
|
void |
prune()
Removes expired cache entries.
|
void |
reset()
Removes all entries in the cache.
|
void |
setMaxSize(long maxSize) |
void |
store(String key,
CacheEntry entry)
Stores an entry in the cache.
|
public InProcessMemoryCache()
public InProcessMemoryCache(long maxSize)
maxSize
- Initial max size in bytespublic long getSize()
public long getMaxSize()
setMaxSize(long)
public void setMaxSize(long maxSize)
maxSize
- Max size in bytesgetMaxSize()
public void store(String key, CacheEntry entry)
Cache
CacheEntry.getExpirationDate()
, although it may very well
be un-fetchable sooner.
Keys are unique to the cache. Storing for a key that already exists will replace the entry if it exists.
public CacheEntry fetch(String key)
Cache
public void invalidate(String tag)
Cache
invalidate
in interface Cache
tag
- The cache tagpublic void prune()
Cache
Copyright © 2009-2016 Three Crickets LLC.