public class ObjectCache<KEY,VALUE> extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ObjectCache.ReferenceType |
| Constructor and Description |
|---|
ObjectCache(ObjectCache.ReferenceType referenceType,
int maxSize,
long expirationMillis)
Create a cache according to the given configuration.
|
| Modifier and Type | Method and Description |
|---|---|
int |
cleanUpObsoleteEntries()
Iterates over all entries to check for obsolete ones (time expired or reference cleared).
|
void |
clear()
Clears all cached entries.
|
boolean |
containsKey(KEY key) |
boolean |
containsKeyWithValue(KEY key) |
void |
evictToTargetSize(int targetSize) |
VALUE |
get(KEY key)
Get the cached entry or null if no valid cached entry is found.
|
int |
getCountEvicted() |
int |
getCountExpired() |
int |
getCountHit() |
int |
getCountMiss() |
int |
getCountPut() |
int |
getCountRefCleared() |
int |
getMaxSize() |
String |
getStatsStringRemoved()
Often used in addition to
toString() to print out states: details why entries were removed. |
Set<KEY> |
keySet() |
VALUE |
put(KEY key,
VALUE object)
Stores an new entry in the cache.
|
void |
putAll(Map<KEY,VALUE> mapDataToPut)
Stores all entries contained in the given map in the cache.
|
VALUE |
remove(KEY key)
Removes an entry from the cache.
|
int |
size() |
String |
toString() |
public ObjectCache(ObjectCache.ReferenceType referenceType, int maxSize, long expirationMillis)
referenceType - SOFT is usually a good choice allowing the VM to clear caches when running low on
memory.
STRONG may also be preferred, e.g. when the required space is granted.maxSize - The maximum number of entries stored by this cacheexpirationMillis - public void putAll(Map<KEY,VALUE> mapDataToPut)
public void clear()
public void evictToTargetSize(int targetSize)
public int cleanUpObsoleteEntries()
Note: Usually you don't need to call this method explicitly, because it is called internally in certain conditions when space has to be reclaimed.
public boolean containsKey(KEY key)
public boolean containsKeyWithValue(KEY key)
public int getMaxSize()
public int size()
public int getCountPut()
public int getCountHit()
public int getCountMiss()
public int getCountExpired()
public int getCountRefCleared()
public int getCountEvicted()
public String getStatsStringRemoved()
toString() to print out states: details why entries were removed.Copyright © 2016. All rights reserved.