public class ObjectCache<KEY,VALUE>
extends java.lang.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() |
java.lang.String |
getStatsStringRemoved()
Often used in addition to
toString() to print out states: details why entries were removed. |
java.util.Set<KEY> |
keySet() |
VALUE |
put(KEY key,
VALUE object)
Stores an new entry in the cache.
|
void |
putAll(java.util.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() |
java.lang.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(java.util.Map<KEY,VALUE> mapDataToPut)
public void clear()
public void evictToTargetSize(int targetSize)
public int cleanUpObsoleteEntries()
public boolean containsKey(KEY key)
public boolean containsKeyWithValue(KEY key)
public java.util.Set<KEY> keySet()
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 java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getStatsStringRemoved()
toString()
to print out states: details why entries were removed.Available under the Apache License, Version 2.0 - Copyright © 2012-2016 greenrobot.org. All Rights Reserved.