public class ContentCache
extends java.lang.Object
The file-content caching is initiated by calling tryCache(FileIO, String,
long)
. Given a FileIO, a file location string, and file length that is within allowed limit,
ContentCache will return a CachingInputFile
that is backed by the cache. Calling CachingInputFile#newStream()
will return a ByteBufferInputStream
backed by list of
ByteBuffer
from the cache if such file-content exist in the cache. If the file-content
does not exist in the cache yet, a regular InputFile will be instantiated, read-ahead, and loaded
into the cache before returning ByteBufferInputStream. The regular InputFile is also used as a
fallback if cache loading fail.
Constructor and Description |
---|
ContentCache(long expireAfterAccessMs,
long maxTotalBytes,
long maxContentLength)
Constructor for ContentCache class.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanUp() |
long |
estimatedCacheSize() |
long |
expireAfterAccess() |
org.apache.iceberg.io.ContentCache.CacheEntry |
get(java.lang.String key,
java.util.function.Function<java.lang.String,org.apache.iceberg.io.ContentCache.CacheEntry> mappingFunction) |
org.apache.iceberg.io.ContentCache.CacheEntry |
getIfPresent(java.lang.String location) |
void |
invalidate(java.lang.String key) |
void |
invalidateAll() |
long |
maxContentLength() |
long |
maxTotalBytes() |
com.github.benmanes.caffeine.cache.stats.CacheStats |
stats() |
java.lang.String |
toString() |
InputFile |
tryCache(FileIO io,
java.lang.String location,
long length)
Try cache the file-content of file in the given location upon stream reading.
|
public ContentCache(long expireAfterAccessMs, long maxTotalBytes, long maxContentLength)
expireAfterAccessMs
- controls the duration for which entries in the ContentCache are hold
since last access. Must be greater or equal than 0. Setting 0 means cache entries expire
only if it gets evicted due to memory pressure.maxTotalBytes
- controls the maximum total amount of bytes to cache in ContentCache. Must
be greater than 0.maxContentLength
- controls the maximum length of file to be considered for caching. Must
be greater than 0.public long expireAfterAccess()
public long maxContentLength()
public long maxTotalBytes()
public com.github.benmanes.caffeine.cache.stats.CacheStats stats()
public org.apache.iceberg.io.ContentCache.CacheEntry get(java.lang.String key, java.util.function.Function<java.lang.String,org.apache.iceberg.io.ContentCache.CacheEntry> mappingFunction)
public org.apache.iceberg.io.ContentCache.CacheEntry getIfPresent(java.lang.String location)
public InputFile tryCache(FileIO io, java.lang.String location, long length)
If length is longer than maximum length allowed by ContentCache, a regular InputFile
and no caching will be done for that file. Otherwise, this method will return a CachingInputFile
that serve file reads backed by ContentCache.
io
- a FileIO associated with the location.location
- URL/path of a file accessible by io.length
- the known length of such file.CachingInputFile
if length is within allowed limit. Otherwise, a regular
InputFile
for given location.public void invalidate(java.lang.String key)
public void invalidateAll()
public void cleanUp()
public long estimatedCacheSize()
public java.lang.String toString()
toString
in class java.lang.Object