Package org.apache.tika.io
Class CacheMemoryBudget
java.lang.Object
org.apache.tika.io.CacheMemoryBudget
A shared, bounded memory budget for in-memory stream caching.
When present, stream caches hold content in memory past the per-object threshold by
reserving buffer capacity against this budget, spilling to a temp file when a
reservation fails. Content up to the per-object threshold is not accounted here. Place a
single, process-wide instance in the ParseContext; it is
bridged to the IO layer via TikaInputStream.enableRewind(CacheMemoryBudget).
Thread-safe; a single instance may be shared across concurrent parses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlonglongvoidrelease(long n) Releasesnpreviously-reserved bytes back to the budget.longtryReserve(long n) Attempts to reservenbytes.
-
Constructor Details
-
CacheMemoryBudget
public CacheMemoryBudget(long maxBytes) - Parameters:
maxBytes- maximum total bytes that may be held in memory across all caches sharing this budget; must be positive (to disable budgeting, pass no budget at all)
-
-
Method Details
-
tryReserve
public long tryReserve(long n) Attempts to reservenbytes. All-or-nothing: either the full amount is reserved (returnn) or nothing is (return0, signalling the caller to spill).- Parameters:
n- bytes requested- Returns:
nif reserved, else0
-
release
public void release(long n) Releasesnpreviously-reserved bytes back to the budget. -
getMaxBytes
public long getMaxBytes() -
getReservedBytes
public long getReservedBytes()
-