Top Description Inners Fields Constructors Methods
io.undertow.server.handlers.cache

public Class LRUCache<K, V>

extends Object
Class Inheritance
Imports
java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, .AtomicReferenceFieldUpdater, io.undertow.util.ConcurrentDirectDeque

A non-blocking cache where entries are indexed by a key.

To reduce contention, entry allocation and eviction execute in a sampling fashion (entry hits modulo N). Eviction follows an LRU approach (oldest sampled entries are removed first) when the cache is out of capacity.

This cache can also be configured to run in FIFO mode, rather than LRU.

Authors
Jason T. Greene, Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final ConcurrentDirectDeque<LRUCache.CacheEntry<K, V>>
private final ConcurrentMap<K, LRUCache.CacheEntry<K, V>>
private final boolean
private final int
maxAge

How long an item can stay in the cache in milliseconds

private final int
maxEntries

Max active entries that are present in the cache.

private static final int

Constructor Summary

AccessConstructor and Description
public
LRUCache(int maxEntries, final int maxAge)

public
LRUCache(int maxEntries, final int maxAge, boolean fifo)

Method Summary

Modifier and TypeMethod and Description
public void
add(K key, V newValue)

private void
bumpAccess(LRUCache.CacheEntry<K, V> cacheEntry)

public void
public V
get(K key)

public V
remove(K key)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessQueueback to summary
private final ConcurrentDirectDeque<LRUCache.CacheEntry<K, V>> accessQueue
cacheback to summary
private final ConcurrentMap<K, LRUCache.CacheEntry<K, V>> cache
fifoback to summary
private final boolean fifo
maxAgeback to summary
private final int maxAge

How long an item can stay in the cache in milliseconds

maxEntriesback to summary
private final int maxEntries

Max active entries that are present in the cache.

SAMPLE_INTERVALback to summary
private static final int SAMPLE_INTERVAL

Constructor Detail

LRUCacheback to summary
public LRUCache(int maxEntries, final int maxAge)
LRUCacheback to summary
public LRUCache(int maxEntries, final int maxAge, boolean fifo)

Method Detail

addback to summary
public void add(K key, V newValue)
bumpAccessback to summary
private void bumpAccess(LRUCache.CacheEntry<K, V> cacheEntry)
clearback to summary
public void clear()
getback to summary
public V get(K key)
removeback to summary
public V remove(K key)
io.undertow.server.handlers.cache back to summary

public final Class LRUCache.CacheEntry<K, V>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private volatile Object
private static final Object
private final long
private volatile int
private static final AtomicIntegerFieldUpdater<LRUCache.CacheEntry<K, V>>
private final K
private static final AtomicReferenceFieldUpdater<LRUCache.CacheEntry<K, V>, Object>
private volatile V

Constructor Summary

AccessConstructor and Description
private
CacheEntry(K key, V value, final long expires)

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
pack-priv Object
public long
public V
public int
hit()

public K
key()

pack-priv boolean
public void
setValue(final V value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessTokenback to summary
private volatile Object accessToken
CLAIM_TOKENback to summary
private static final Object CLAIM_TOKEN
expiresback to summary
private final long expires
hitsback to summary
private volatile int hits
hitsUpdaterback to summary
private static final AtomicIntegerFieldUpdater<LRUCache.CacheEntry<K, V>> hitsUpdater
keyback to summary
private final K key
tokenUpdatorback to summary
private static final AtomicReferenceFieldUpdater<LRUCache.CacheEntry<K, V>, Object> tokenUpdator
valueback to summary
private volatile V value

Constructor Detail

CacheEntryback to summary
private CacheEntry(K key, V value, final long expires)

Method Detail

claimTokenback to summary
pack-priv Object claimToken()
clearTokenback to summary
pack-priv Object clearToken()
getExpiresback to summary
public long getExpires()
getValueback to summary
public V getValue()
hitback to summary
public int hit()
keyback to summary
public K key()
setTokenback to summary
pack-priv boolean setToken(Object token)
setValueback to summary
public void setValue(final V value)