Class ObjectCache<KEY,VALUE>
java.lang.Object
org.greenrobot.essentials.ObjectCache<KEY,VALUE>
An in-memory object cache supporting soft/weak/strong references, maximum size (clearing the entries that were put
first), and time-based expiration.
- Author:
- markus
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionObjectCache(ObjectCache.ReferenceType referenceType, int maxSize, long expirationMillis) Create a cache according to the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionintIterates over all entries to check for obsolete ones (time expired or reference cleared).voidclear()Clears all cached entries.booleancontainsKey(KEY key) booleancontainsKeyWithValue(KEY key) voidevictToTargetSize(int targetSize) Get the cached entry or null if no valid cached entry is found.intintintintintintintOften used in addition totoString()to print out states: details why entries were removed.keySet()Stores an new entry in the cache.voidStores all entries contained in the given map in the cache.Removes an entry from the cache.intsize()toString()
-
Constructor Details
-
ObjectCache
Create a cache according to the given configuration.- Parameters:
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-
-
-
Method Details
-
put
-
putAll
-
get
-
clear
public void clear()Clears all cached entries. -
remove
-
evictToTargetSize
public void evictToTargetSize(int targetSize) -
cleanUpObsoleteEntries
public int cleanUpObsoleteEntries()Iterates over all entries to check for obsolete ones (time expired or reference cleared). 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. -
containsKey
-
containsKeyWithValue
-
keySet
-
getMaxSize
public int getMaxSize() -
size
public int size() -
getCountPut
public int getCountPut() -
getCountHit
public int getCountHit() -
getCountMiss
public int getCountMiss() -
getCountExpired
public int getCountExpired() -
getCountRefCleared
public int getCountRefCleared() -
getCountEvicted
public int getCountEvicted() -
toString
-
getStatsStringRemoved
Often used in addition totoString()to print out states: details why entries were removed.
-