Class ContentCache
- java.lang.Object
-
- org.apache.iceberg.io.ContentCache
-
public class ContentCache extends java.lang.Object
Class that provides file-content caching during reading.The file-content caching is initiated by calling
tryCache(InputFile)
. Given a FileIO, a file location string, and file length that is within allowed limit, ContentCache will return aContentCache.CachingInputFile
that is backed by the cache. CallingContentCache.CachingInputFile.newStream()
will return aByteBufferInputStream
backed by list ofByteBuffer
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 Summary
Constructors Constructor Description ContentCache(long expireAfterAccessMs, long maxTotalBytes, long maxContentLength)
Constructor for ContentCache class.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
cleanUp()
long
estimatedCacheSize()
long
expireAfterAccess()
void
invalidate(java.lang.String key)
Invalidate the cache entry for the given key.void
invalidateAll()
Deprecated.since 1.7.0, will be removed in 2.0.0; This method does only best-effort invalidation and is susceptible to a race condition.long
maxContentLength()
long
maxTotalBytes()
com.github.benmanes.caffeine.cache.stats.CacheStats
stats()
java.lang.String
toString()
InputFile
tryCache(InputFile input)
Try cache the file-content of file in the given location upon stream reading.
-
-
-
Constructor Detail
-
ContentCache
public ContentCache(long expireAfterAccessMs, long maxTotalBytes, long maxContentLength)
Constructor for ContentCache class.- Parameters:
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.
-
-
Method Detail
-
expireAfterAccess
public long expireAfterAccess()
-
maxContentLength
public long maxContentLength()
-
maxTotalBytes
public long maxTotalBytes()
-
stats
public com.github.benmanes.caffeine.cache.stats.CacheStats stats()
-
tryCache
public InputFile tryCache(InputFile input)
Try cache the file-content of file in the given location upon stream reading.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 aContentCache.CachingInputFile
that serve file reads backed by ContentCache.- Parameters:
input
- an InputFile to cache- Returns:
- a
ContentCache.CachingInputFile
if length is within allowed limit. Otherwise, a regularInputFile
for given location.
-
invalidate
public void invalidate(java.lang.String key)
Invalidate the cache entry for the given key.Note: if there is ongoing load, this is a blocking operation, i.e. it will wait for the load to complete before invalidating the entry.
-
invalidateAll
@Deprecated public void invalidateAll()
Deprecated.since 1.7.0, will be removed in 2.0.0; This method does only best-effort invalidation and is susceptible to a race condition. If the caller changed the state that could be cached (perhaps files on the storage) and calls this method, there is no guarantee that the cache will not contain stale entries some time after this method returns.
-
cleanUp
public void cleanUp()
-
estimatedCacheSize
public long estimatedCacheSize()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-