java.lang.Object
com.maxmind.db.CHMCache
- All Implemented Interfaces:
NodeCache
A simplistic cache using a
ConcurrentHashMap. There's no eviction policy, it just fills up until reaching the specified capacity (or close enough at least, bounds check is not atomic :)Nested Class Summary
Nested classes/interfaces inherited from interface NodeCache
NodeCache.LoaderModifier and TypeInterfaceDescriptionstatic interfaceInterface for loading nodes on cache miss.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConcurrentHashMap<Integer, Object> The cached values, by key.private booleanTrue once the capacity has been reached.private final intMost entries the cache holds.private static final intEntries held when no capacity is given.Constructor Summary
Method Summary
All MethodsModifier and TypeMethodDescriptionget(int key, NodeCache.Loader loader) Get a value from the cache, loading it if necessary.
Field Details
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITYEntries held when no capacity is given.- See Also:
capacity
private final int capacityMost entries the cache holds.cache
The cached values, by key.cacheFull
private boolean cacheFullTrue once the capacity has been reached.
Constructor Details
CHMCache
public CHMCache()Create a cache with default capacity.CHMCache
public CHMCache(int capacity) Create a cache with the given capacity.- Parameters:
capacity- the maximum number of entries
Method Details
get
Description copied from interface:NodeCacheGet a value from the cache, loading it if necessary.- Specified by:
getin interfaceNodeCache- Parameters:
key- the cache keyloader- the loader to use if the key is not in cache- Returns:
- the cached or loaded value
- Throws:
IOException- if loading fails