Class CacheMemoryBudget

java.lang.Object
org.apache.tika.io.CacheMemoryBudget

public final class CacheMemoryBudget extends Object
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 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 reserve n bytes. All-or-nothing: either the full amount is reserved (return n) or nothing is (return 0, signalling the caller to spill).
      Parameters:
      n - bytes requested
      Returns:
      n if reserved, else 0
    • release

      public void release(long n)
      Releases n previously-reserved bytes back to the budget.
    • getMaxBytes

      public long getMaxBytes()
    • getReservedBytes

      public long getReservedBytes()