
public class SynchronizedLruCache<K,V> extends AbstractLruCache<K,V>
This cache implementation should be used with low number of threads.
| Constructor and Description |
|---|
SynchronizedLruCache(int capacity,
long ttl)
Creates new SynchronizedLruCache with DEFAULT_LOAD_FACTOR and
DEFAULT_INITIAL_CAPACITY
|
SynchronizedLruCache(int capacity,
long ttl,
int initialCapacity)
Creates new SynchronizedLruCache with DEFAULT_LOAD_FACTOR
|
SynchronizedLruCache(int capacity,
long ttl,
int initialCapacity,
float loadFactor)
Creates new SynchronizedLruCache
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all entries from cache
|
int |
forceClearOldest()
Removes all oldest entries from cache (ttl based)
|
V |
get(K key)
Returns value cached with key.
|
int |
getCapacity()
Returns cache capacity
|
protected InterfaceLruCacheEntry<V> |
getEntry(K key)
Returns LruCacheEntry mapped by key or null if it does not exist
|
void |
put(K key,
V value,
long ttl)
Puts value under key into cache with desired TTL
|
protected void |
putEntry(K key,
InterfaceLruCacheEntry<V> entry)
Puts entry into cache
|
V |
remove(K key)
Removes entry from cache (if exists)
|
int |
size()
Returns number of entries stored in cache (including invalid ones)
|
public SynchronizedLruCache(int capacity,
long ttl,
int initialCapacity,
float loadFactor)
capacity - max cache capacityttl - time to live in millisecondsinitialCapacity - initial cache capacityloadFactor - public SynchronizedLruCache(int capacity,
long ttl,
int initialCapacity)
capacity - max cache capacityttl - time to live in millisecondsinitialCapacity - initial cache capacitypublic SynchronizedLruCache(int capacity,
long ttl)
capacity - max cache capacityttl - time to live in millisecondspublic void clear()
InterfaceLruCachepublic V get(K key)
InterfaceLruCacheget in interface InterfaceLruCache<K,V>get in class AbstractLruCache<K,V>public int getCapacity()
InterfaceLruCacheprotected InterfaceLruCacheEntry<V> getEntry(K key)
AbstractLruCachegetEntry in class AbstractLruCache<K,V>public int size()
InterfaceLruCachepublic void put(K key, V value, long ttl)
InterfaceLruCacheput in interface InterfaceLruCache<K,V>put in class AbstractLruCache<K,V>ttl - time to live in millisecondsprotected void putEntry(K key, InterfaceLruCacheEntry<V> entry)
AbstractLruCacheputEntry in class AbstractLruCache<K,V>public V remove(K key)
InterfaceLruCachepublic int forceClearOldest()
InterfaceLruCacheCopyright © 2009–2020 Waarp. All rights reserved.