Evictions
Configure evictions of cached files.
Evictions to the cache occur automatically but you can also evict any cached file by hand by calling:
// assuming that localMediaFileCacheService and mediaStorageConfigService are taken from Spring context
MediaFolderConfig folderConfig = mediaStorageConfigService.getConfigForFolder("folderQualifier");
String locationInStorage = "some/location/foo.jpg";
localMediaFileCacheService.removeFromCache(folderConfig, locationInStorage);
When eviction is done automatically, the underlying logic takes care about cached file removal. A file is removed only when the last client releases the usage by closing the stream. One exception to this rule is when the client asks for the real File object to cached file instead of InputStream. In this case such a cached file, when evicted, isn’t removed from the cache but a special zero-bytes marker is created in the cache directory. Such marked files will stay in the cache to the next restart of the Platform and then removed on Platform startup. It's also safe to delete such files (together with marker files) directly using operating system commands. See an example of a cached file and its eviction marker:
/h0f/h72/ODc5NjE4NzM2MTMxMC8zMDgzMS5qcGc=__H__c9690cd1-10e0-436b-9ce0-b509a5b0c721.bin /h0f/h72/ODc5NjE4NzM2MTMxMC8zMDgzMS5qcGc=__H__c9690cd1-10e0-436b-9ce0-b509a5b0c721.bin.EVICTED
Periodical Clearing of Evicted Files
As evicted files are only deleted after a Platform startup, large numbers of these files can accumulate over time, resulting in degraded responsiveness or the storefront or, in extreme cases, storefront downtime. To ensure that evicted files are cleared from the local cache at regular intervals, use the following property:
media.cache.cleanup.evicted.files.enabled
When set to true, evicted files are removed periodically from the local cache. The default value is false. To configure the intervals at which the local cache is cleared, use the following property:
media.cache.cleanup.period.minutes
The default value is 30 minutes. The media.cache.cleanup.period.minutes property works only when media.cache.cleanup.evicted.files.enabled is set to true.