Class DirectBufferCache
- java.lang.Object
-
- io.undertow.server.handlers.cache.DirectBufferCache
-
public class DirectBufferCache extends java.lang.ObjectA 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 Class Summary
Nested Classes Modifier and Type Class Description static classDirectBufferCache.CacheEntry
-
Field Summary
Fields Modifier and Type Field Description static intMAX_AGE_NO_CACHINGMax age 0, indicating that entries expire upon creation and are not retained;static intMAX_AGE_NO_EXPIRYMage age -1, entries dont expire
-
Constructor Summary
Constructors Constructor Description DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory)DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, org.xnio.BufferAllocator<java.nio.ByteBuffer> bufferAllocator)DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, org.xnio.BufferAllocator<java.nio.ByteBuffer> bufferAllocator, int maxAge)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DirectBufferCache.CacheEntryadd(java.lang.Object key, int size)DirectBufferCache.CacheEntryadd(java.lang.Object key, int size, int maxAge)DirectBufferCache.CacheEntryget(java.lang.Object key)java.util.Set<java.lang.Object>getAllKeys()Returns a set of all the keys in the cache.voidremove(java.lang.Object key)
-
-
-
Field Detail
-
MAX_AGE_NO_CACHING
public static final int MAX_AGE_NO_CACHING
Max age 0, indicating that entries expire upon creation and are not retained;- See Also:
- Constant Field Values
-
MAX_AGE_NO_EXPIRY
public static final int MAX_AGE_NO_EXPIRY
Mage age -1, entries dont expire- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DirectBufferCache
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory)
-
DirectBufferCache
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, org.xnio.BufferAllocator<java.nio.ByteBuffer> bufferAllocator)
-
DirectBufferCache
public DirectBufferCache(int sliceSize, int slicesPerPage, int maxMemory, org.xnio.BufferAllocator<java.nio.ByteBuffer> bufferAllocator, int maxAge)
-
-
Method Detail
-
add
public DirectBufferCache.CacheEntry add(java.lang.Object key, int size)
-
add
public DirectBufferCache.CacheEntry add(java.lang.Object key, int size, int maxAge)
-
get
public DirectBufferCache.CacheEntry get(java.lang.Object key)
-
getAllKeys
public java.util.Set<java.lang.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:
- all the keys in this cache
-
remove
public void remove(java.lang.Object key)
-
-