Key - Value - public class LRUCache<Key,Value> extends Object implements HGCache<Key,Value>, CloseMe
Implements a cache that keeps most recently used elements in memory while discarding the least recently used ones. Evicting elements is done in chunks determined by a percentage of the current cache's size - see the constructors for more info.
| Constructor and Description |
|---|
LRUCache() |
LRUCache(float usedMemoryThreshold,
float evictPercent) |
LRUCache(int maxSize,
int evictCount) |
LRUCache(ReadWriteLock lockImplementation) |
| Modifier and Type | Method and Description |
|---|---|
void |
checkConsistent()
Check that the map contains exactly the same elements as the linked list.
|
void |
clear()
Clear (i.e.
|
void |
clearNonBlocking() |
void |
close() |
protected void |
finalize() |
Value |
get(Key key)
Retrieve an element from the cache.
|
Value |
getIfLoaded(Key key)
Retrieve and return an element from the cache if it's already there or
return
null otherwise. |
RefResolver<Key,Value> |
getResolver()
Return the
RefResolver used to load data in the cache. |
boolean |
isLoaded(Key key)
Return
true if the element with the given key is currently in the
cache and false otherwise. |
void |
remove(Key key)
Force removal of an element from the cache.
|
void |
setLockImplementation(ReadWriteLock lockImplementation) |
void |
setResolver(RefResolver<Key,Value> resolver)
Set the
RefResolver to be used to load data in the cache. |
int |
size()
Return the number of elements currently in the cache.
|
public LRUCache()
public LRUCache(ReadWriteLock lockImplementation)
public LRUCache(int maxSize,
int evictCount)
maxSize - The maximum number of elements allowed in the cache.evictCount - The number of (least used) elements to evict when
the cache reaches its maximum.public LRUCache(float usedMemoryThreshold,
float evictPercent)
usedMemoryThreshold - The percentage of total memory that
must become used before the cache decides to evict elements (e.g.
a value of 0.9 means the cache will evict elements when 90% of memory
is currently in use).evictPercent - The percentage of elements to evict when the
usedMemoryThreshold is reached.public Value get(Key key)
HGCacheRetrieve an element from the cache. If the element is already in the cache,
it is simply returned. Otherwise, the RefResolver will be used to
obtain it automatically from permanent storage.
public Value getIfLoaded(Key key)
HGCacheRetrieve and return an element from the cache if it's already there or
return null otherwise. This method will not call the
RefResolver when the element is not found in the cache.
getIfLoaded in interface HGCache<Key,Value>key - The key of the element.null is it's not found in the cache.public boolean isLoaded(Key key)
HGCacheReturn true if the element with the given key is currently in the
cache and false otherwise.
public void remove(Key key)
HGCacheForce removal of an element from the cache. This method is generally used when the data has been (or is being) removed from the permanent storage as well.
public RefResolver<Key,Value> getResolver()
HGCacheReturn the RefResolver used to load data in the cache.
getResolver in interface HGCache<Key,Value>public void setResolver(RefResolver<Key,Value> resolver)
HGCacheSet the RefResolver to be used to load data in the cache.
setResolver in interface HGCache<Key,Value>public void clear()
HGCacheClear (i.e. force removal of) all elements from the cache.
public void clearNonBlocking()
public void checkConsistent()
public void setLockImplementation(ReadWriteLock lockImplementation)
Copyright © 2015. All rights reserved.