Package fr.gouv.vitam.workspace.common
Class WorkspaceThresholdCache
java.lang.Object
fr.gouv.vitam.workspace.common.WorkspaceThresholdCache
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longlonggetUsedBytes(int tenantId) voidLoads the cache fromroot/threshold-cache.jsonwhen present.voidPersists the current cache toroot/threshold-cache.json.voidRecomputes the per-tenant used space from disk, keeping the previous value for any tenant whose computation exceeds 30L seconds, then persists the result.voidstart()Loads the persisted cache, triggers a first asynchronous refresh (non blocking) and schedules the periodic refresh.
-
Constructor Details
-
WorkspaceThresholdCache
-
-
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
0when 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 toroot/threshold-cache.json. -
loadFromDisk
public void loadFromDisk()Loads the cache fromroot/threshold-cache.jsonwhen present. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-