Class WorkspaceThresholdCache

java.lang.Object
fr.gouv.vitam.workspace.common.WorkspaceThresholdCache
All Implemented Interfaces:
AutoCloseable

public class WorkspaceThresholdCache extends Object implements AutoCloseable
Holds the per-tenant workspace usage (in bytes), refreshed periodically from disk.

The cache is recomputed entirely from disk (one Files.walk per tenant directory under root/tenantId), never incrementally on put/delete. Between two refreshes the cached values do not move. After each refresh the values are persisted to root/threshold-cache.json for a fast restart: on start() the file is loaded first, then a full refresh is launched asynchronously so the server start is never blocked. If the computation of a single tenant exceeds 30L seconds, the previous value is kept and a warning is logged.

  • Constructor Summary

    Constructors
    Constructor
    Description
    WorkspaceThresholdCache(Path storageRoot, long refreshIntervalSeconds)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    long
     
    long
    getUsedBytes(int tenantId)
     
    void
    Loads the cache from root/threshold-cache.json when present.
    void
    Persists the current cache to root/threshold-cache.json.
    void
    Recomputes the per-tenant used space from disk, keeping the previous value for any tenant whose computation exceeds 30L seconds, then persists the result.
    void
    Loads the persisted cache, triggers a first asynchronous refresh (non blocking) and schedules the periodic refresh.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WorkspaceThresholdCache

      public WorkspaceThresholdCache(Path storageRoot, long refreshIntervalSeconds)
  • Method Details

    • start

      public void start()
      Loads the persisted cache, triggers a first asynchronous refresh (non blocking) and schedules the periodic refresh.
    • getUsedBytes

      public long getUsedBytes(int tenantId)
      Parameters:
      tenantId - the tenant id
      Returns:
      the cached used space (in bytes) for the tenant, or 0 when unknown
    • getTotalUsedBytes

      public long getTotalUsedBytes()
      Returns:
      the cached total used space (in bytes) across all tenants
    • refreshFromDisk

      public void refreshFromDisk()
      Recomputes the per-tenant used space from disk, keeping the previous value for any tenant whose computation exceeds 30L seconds, then persists the result.
    • persistToDisk

      public void persistToDisk()
      Persists the current cache to root/threshold-cache.json.
    • loadFromDisk

      public void loadFromDisk()
      Loads the cache from root/threshold-cache.json when present.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable