Package org.jgroups.blocks
Class Cache<K,V>
java.lang.Object
org.jgroups.blocks.Cache<K,V>
Simple cache which maintains keys and value. A reaper can be enabled which periodically evicts expired entries.
Also, when the cache is configured to be bounded, entries in excess of the max size will be evicted on put().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceprivate classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Set<Cache.ChangeListener> private final AtomicBooleanprivate static final Logprivate final ConcurrentMap<K, Cache.Value<V>> private intThe maximum number of keys, When this value is exceeded we evict older entries, until we drop below this mark again.private Futureprivate ScheduledThreadPoolExecutor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoiddump()voidenableReaping(long interval) Runs the reaper every interval ms, evicts expired itemsSet<Map.Entry<K, Cache.Value<V>>> entrySet()private voidevict()This method should not be used to add or remove elements ! It was just added because ReplCacheDemo requires it for its data modelintintgetSize()private VgetValue(Cache.Value<V> val) private booleanisExpired(Cache.Value<V> val) booleanprivate voidvoidvoidsetMaxNumberOfEntries(int max_num_entries) voidstart()voidstop()toString()
-
Field Details
-
log
-
map
-
timer
-
task
-
is_reaping
-
change_listeners
-
max_num_entries
private int max_num_entriesThe maximum number of keys, When this value is exceeded we evict older entries, until we drop below this mark again. This effectively maintains a bounded cache. A value of 0 means don't bound the cache.
-
-
Constructor Details
-
Cache
public Cache()
-
-
Method Details
-
getMaxNumberOfEntries
public int getMaxNumberOfEntries() -
setMaxNumberOfEntries
public void setMaxNumberOfEntries(int max_num_entries) -
addChangeListener
-
removeChangeListener
-
getSize
public int getSize() -
isReapingEnabled
public boolean isReapingEnabled() -
enableReaping
public void enableReaping(long interval) Runs the reaper every interval ms, evicts expired items -
disableReaping
public void disableReaping() -
start
public void start() -
stop
public void stop() -
put
- Parameters:
key-val-caching_time- Number of milliseconds to keep an entry in the cache. -1 means don't cache (if reaping is enabled, we'll evict an entry with -1 caching time), 0 means never evict. In the latter case, we can still evict an entry with 0 caching time: when we have a bounded cache, we evict in order of insertion no matter what the caching time is.
-
get
-
getInternalMap
This method should not be used to add or remove elements ! It was just added because ReplCacheDemo requires it for its data model- Returns:
-
getEntry
-
remove
-
entrySet
-
toString
-
dump
-
evict
private void evict() -
notifyChangeListeners
private void notifyChangeListeners() -
getValue
-
isExpired
-