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

public Class DirectBufferCache

extends Object
Class Inheritance
Static Imports
io.undertow.server.handlers.cache.LimitedBufferSlicePool.PooledByteBuffer

A non-blocking buffer cache where entries are indexed by a path and are made up of a subsequence of blocks in a fixed large direct buffer. An ideal application is a file system cache, where the path corresponds to a file location.

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

In order to expedite reclamation, cache entries are reference counted as opposed to garbage collected.

Author
Jason T. Greene

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final ConcurrentDirectDeque<DirectBufferCache.CacheEntry>
private final ConcurrentMap<Object, DirectBufferCache.CacheEntry>
private final int
private final LimitedBufferSlicePool
private static final int
private final int

Constructor Summary

AccessConstructor and Description
public
DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory)

public
DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, final BufferAllocator<ByteBuffer> bufferAllocator)

public
DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, final BufferAllocator<ByteBuffer> bufferAllocator, int maxAge)

Method Summary

Modifier and TypeMethod and Description
public DirectBufferCache.CacheEntry
add(Object key, int size)

public DirectBufferCache.CacheEntry
add(Object key, int size, int maxAge)

private void
public DirectBufferCache.CacheEntry
get(Object key)

public Set<Object>

Returns:

all the keys in this cache
getAllKeys
()

Returns a set of all the keys in the cache.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessQueueback to summary
private final ConcurrentDirectDeque<DirectBufferCache.CacheEntry> accessQueue
cacheback to summary
private final ConcurrentMap<Object, DirectBufferCache.CacheEntry> cache
maxAgeback to summary
private final int maxAge
poolback to summary
private final LimitedBufferSlicePool pool
SAMPLE_INTERVALback to summary
private static final int SAMPLE_INTERVAL
sliceSizeback to summary
private final int sliceSize

Constructor Detail

DirectBufferCacheback to summary
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory)
DirectBufferCacheback to summary
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, final BufferAllocator<ByteBuffer> bufferAllocator)
DirectBufferCacheback to summary
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, final BufferAllocator<ByteBuffer> bufferAllocator, int maxAge)

Method Detail

addback to summary
public DirectBufferCache.CacheEntry add(Object key, int size)
addback to summary
public DirectBufferCache.CacheEntry add(Object key, int size, int maxAge)
bumpAccessback to summary
private void bumpAccess(DirectBufferCache.CacheEntry cacheEntry)
getback to summary
public DirectBufferCache.CacheEntry get(Object key)
getAllKeysback to summary
public Set<Object> getAllKeys()

Returns a set of all the keys in the cache. This is a copy of the key set at the time of method invocation.

Returns:Set<Object>

all the keys in this cache

removeback to summary
public void remove(Object key)
io.undertow.server.handlers.cache back to summary

public final Class DirectBufferCache.CacheEntry

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.cache.DirectBufferCache.CacheEntry

Field Summary

Modifier and TypeField and Description
private volatile Object
private volatile LimitedBufferSlicePool.PooledByteBuffer[]
private static final AtomicReferenceFieldUpdater<DirectBufferCache.CacheEntry, LimitedBufferSlicePool.PooledByteBuffer[]>
private final DirectBufferCache
private static final Object
private static final LimitedBufferSlicePool.PooledByteBuffer[]
private volatile int
private static final AtomicIntegerFieldUpdater<DirectBufferCache.CacheEntry>
private volatile long
private volatile int
private static final AtomicIntegerFieldUpdater<DirectBufferCache.CacheEntry>
private static final LimitedBufferSlicePool.PooledByteBuffer[]
private final Object
private final int
private volatile int
private static final AtomicIntegerFieldUpdater<DirectBufferCache.CacheEntry>
private final int
private static final AtomicReferenceFieldUpdater<DirectBufferCache.CacheEntry, Object>

Constructor Summary

AccessConstructor and Description
private
CacheEntry(Object key, int size, DirectBufferCache cache, final int maxAge)

Method Summary

Modifier and TypeMethod and Description
public boolean
public LimitedBufferSlicePool.PooledByteBuffer[]
public boolean
pack-priv Object
pack-priv Object
public boolean
private void
public void
public void
public boolean
pack-priv long
public int
hit()

public Object
key()

public boolean
pack-priv boolean
public int
size()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessTokenback to summary
private volatile Object accessToken
buffersback to summary
private volatile LimitedBufferSlicePool.PooledByteBuffer[] buffers
bufsUpdaterback to summary
private static final AtomicReferenceFieldUpdater<DirectBufferCache.CacheEntry, LimitedBufferSlicePool.PooledByteBuffer[]> bufsUpdater
cacheback to summary
private final DirectBufferCache cache
CLAIM_TOKENback to summary
private static final Object CLAIM_TOKEN
EMPTY_BUFFERSback to summary
private static final LimitedBufferSlicePool.PooledByteBuffer[] EMPTY_BUFFERS
enabledback to summary
private volatile int enabled
enabledUpdatorback to summary
private static final AtomicIntegerFieldUpdater<DirectBufferCache.CacheEntry> enabledUpdator
expiresback to summary
private volatile long expires
hitsback to summary
private volatile int hits
hitsUpdaterback to summary
private static final AtomicIntegerFieldUpdater<DirectBufferCache.CacheEntry> hitsUpdater
INIT_BUFFERSback to summary
private static final LimitedBufferSlicePool.PooledByteBuffer[] INIT_BUFFERS
keyback to summary
private final Object key
maxAgeback to summary
private final int maxAge
refsback to summary
private volatile int refs
refsUpdaterback to summary
private static final AtomicIntegerFieldUpdater<DirectBufferCache.CacheEntry> refsUpdater
sizeback to summary
private final int size
tokenUpdatorback to summary
private static final AtomicReferenceFieldUpdater<DirectBufferCache.CacheEntry, Object> tokenUpdator

Constructor Detail

CacheEntryback to summary
private CacheEntry(Object key, int size, DirectBufferCache cache, final int maxAge)

Method Detail

allocateback to summary
public boolean allocate()
buffersback to summary
public LimitedBufferSlicePool.PooledByteBuffer[] buffers()
claimEnableback to summary
public boolean claimEnable()
claimTokenback to summary
pack-priv Object claimToken()
clearTokenback to summary
pack-priv Object clearToken()
dereferenceback to summary
public boolean dereference()
destroyback to summary
private void destroy()
disableback to summary
public void disable()
enableback to summary
public void enable()
enabledback to summary
public boolean enabled()
getExpiresback to summary
pack-priv long getExpires()
hitback to summary
public int hit()
keyback to summary
public Object key()
referenceback to summary
public boolean reference()
setTokenback to summary
pack-priv boolean setToken(Object token)
sizeback to summary
public int size()