public class LRUHashMapCache<Key,Value> extends Object implements CascadingCache<Key,Value>
CascadingCache
interface backed by a LinkedHashMap
configured to
evict the least recently used key.
That is, if duplicate keys are clustered near each other in the incoming tuple stream, this cache will provide the
most benefit as keys that begin to occur less frequently or not at all will be evicted as the key capacity is reached.
If the keys are very random, if not uniformly distributed in the stream, consider using the
DirectMappedCache
to reduce the amount of hash and equality comparisons.
This implementation is used by default by Unique
and
AggregateBy
and their subclasses.Constructor and Description |
---|
LRUHashMapCache() |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<Key,Value>> |
entrySet() |
Value |
get(Object key) |
int |
getCapacity()
Returns the capacity of this cache.
|
void |
initialize()
Method to initialize the Cache.
|
boolean |
isEmpty() |
Set<Key> |
keySet() |
Value |
put(Key key,
Value value) |
void |
putAll(Map<? extends Key,? extends Value> m) |
Value |
remove(Object key) |
void |
setCacheEvictionCallback(CacheEvictionCallback cacheEvictionCallback)
Sets the
CacheEvictionCallback of this Cache. |
void |
setCapacity(int capacity)
Sets the capacity of the Cache.
|
int |
size() |
Collection<Value> |
values() |
public LRUHashMapCache()
public int getCapacity()
CascadingCache
getCapacity
in interface CascadingCache<Key,Value>
public void setCacheEvictionCallback(CacheEvictionCallback cacheEvictionCallback)
CascadingCache
CacheEvictionCallback
of this Cache.setCacheEvictionCallback
in interface CascadingCache<Key,Value>
public void setCapacity(int capacity)
CascadingCache
setCapacity
in interface CascadingCache<Key,Value>
public void initialize()
CascadingCache
initialize
in interface CascadingCache<Key,Value>
public boolean containsKey(Object key)
containsKey
in interface Map<Key,Value>
public boolean containsValue(Object value)
containsValue
in interface Map<Key,Value>
Copyright © 2007-2015 Concurrent, Inc. All Rights Reserved.