Class StandardQuotaStrategy
- All Implemented Interfaces:
QuotaManagerStrategy,UsageTracker
When a cache file has been written that results in cleanThresholdPct (default 80%) of maxUsageBytes being exceeded then the cached content cleaner is invoked (if not already running) in a new thread.
When the CachingContentStore is about to write a cache file but the disk usage is in excess of panicThresholdPct (default 90%) then the cache file is not written and the cleaner is started (if not already running) in a new thread.
This quota manager works in conjunction with the cleaner to update disk usage levels in memory. When the quota manager shuts down the current disk usage is saved to disk in {ContentCacheImpl.cacheRoot}/cache-usage.ser
Upon startup, if the cache-usage.ser file exists then the current usage is seeded with that value and the cleaner is invoked in a new thread so that the value can be updated more accurately (perhaps some files were deleted manually after shutdown for example).
- Author:
- Matt Ward
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongaddUsageBytes(long sizeDelta) booleanafterWritingCacheFile(long contentSizeBytes) Called immediately after writing a cache file - specifying the size of the file that was written.booleanbeforeWritingCacheFile(long contentSizeBytes) Called immediately before writing a cache file or (when cacheOnInBound is set to true for the CachingContentStore) before handing a ContentWriter to a content producer.longdoubleprotected longintlonglongvoidinit()Lifecycle method.voidsetCache(ContentCacheImpl cache) voidsetCleaner(CachedContentCleaner cleaner) voidsetCleanThresholdPct(int cleanThresholdPct) voidsetCurrentUsageBytes(long newDiskUsage) voidsetMaxFileSizeMB(int maxFileSizeMB) voidsetMaxUsageBytes(long maxUsageBytes) voidsetMaxUsageMB(long maxUsageMB) voidsetNormalCleanThresholdSec(long normalCleanThresholdSec) voidsetPanicThresholdPct(int panicThresholdPct) voidsetTargetUsagePct(int targetUsagePct) voidshutdown()Lifecycle method.
-
Constructor Details
-
StandardQuotaStrategy
public StandardQuotaStrategy()
-
-
Method Details
-
init
public void init()Lifecycle method. Should be called immediately after constructing objects of this type (e.g. by the Spring framework's application context). -
shutdown
public void shutdown()Lifecycle method. Should be called when finished using an object of this type and before the application container is shutdown (e.g. using a Spring framework destroy method). -
beforeWritingCacheFile
public boolean beforeWritingCacheFile(long contentSizeBytes) Description copied from interface:QuotaManagerStrategyCalled immediately before writing a cache file or (when cacheOnInBound is set to true for the CachingContentStore) before handing a ContentWriter to a content producer.In the latter case, the contentSize will be unknown (0), since the content length hasn't been established yet.
- Specified by:
beforeWritingCacheFilein interfaceQuotaManagerStrategy- Parameters:
contentSizeBytes- The size of the content that will be written or 0 if not known.- Returns:
- true to allow the cache file to be written, false to veto.
-
afterWritingCacheFile
public boolean afterWritingCacheFile(long contentSizeBytes) Description copied from interface:QuotaManagerStrategyCalled immediately after writing a cache file - specifying the size of the file that was written. The return value allows implementations control over whether the new cache file is kept (true) or immediately removed (false).- Specified by:
afterWritingCacheFilein interfaceQuotaManagerStrategy- Parameters:
contentSizeBytes- The size of the content that was written.- Returns:
- true to allow the cache file to remain, false to immediately delete.
-
setMaxUsageMB
public void setMaxUsageMB(long maxUsageMB) -
setMaxUsageBytes
public void setMaxUsageBytes(long maxUsageBytes) -
setPanicThresholdPct
public void setPanicThresholdPct(int panicThresholdPct) -
setCleanThresholdPct
public void setCleanThresholdPct(int cleanThresholdPct) -
setTargetUsagePct
public void setTargetUsagePct(int targetUsagePct) -
setNormalCleanThresholdSec
public void setNormalCleanThresholdSec(long normalCleanThresholdSec) -
setCache
-
setCleaner
-
getCurrentUsageBytes
public long getCurrentUsageBytes()- Specified by:
getCurrentUsageBytesin interfaceUsageTracker
-
getCurrentUsageMB
public double getCurrentUsageMB() -
getMaxUsageBytes
public long getMaxUsageBytes() -
getMaxUsageMB
public long getMaxUsageMB() -
getMaxFileSizeMB
public int getMaxFileSizeMB() -
getMaxFileSizeBytes
protected long getMaxFileSizeBytes() -
setMaxFileSizeMB
public void setMaxFileSizeMB(int maxFileSizeMB) -
addUsageBytes
public long addUsageBytes(long sizeDelta) - Specified by:
addUsageBytesin interfaceUsageTracker
-
setCurrentUsageBytes
public void setCurrentUsageBytes(long newDiskUsage) - Specified by:
setCurrentUsageBytesin interfaceUsageTracker
-