Correct way to implement short lived document cache
Question asked by Graham - 12/12/2019 at 5:10 AM
My DocumentCache folder is not cleaning. Our requirement is to delete documents from the cache "soon" after viewing. However, the folder seems not to be cleaning at all.

The application is an ASP.Net MVC application hosted in IIS.

DocumentUltimate version 4.7.0 - am in progress to upgrade to latest (we have a change process).

web.config appsettings:
<add key="CachePath" value="~/App_Data/DocumentCache" />
    <add key="CacheMaxAge" value="-1.00:00:00" />
    <add key="CacheAutoTrimInterval" value="00:5:00" />
    <add key="CacheWaitTimeout" value="00:1:00" />
    <add key="CacheEncryptionEnabled" value="false" />
C# controller
var configuration = new DocumentUltimateWebConfiguration
                CacheLocation = ConfigurationManager.AppSettings["CachePath"],
                CacheMaxAge = TimeSpan.Parse(ConfigurationManager.AppSettings["CacheMaxAge"]),
                CacheAutoTrimInterval = TimeSpan.Parse(ConfigurationManager.AppSettings["CacheAutoTrimInterval"]),
                CacheWaitTimeout = TimeSpan.Parse(ConfigurationManager.AppSettings["CacheWaitTimeout"]),
                CacheEncryptionEnabled = Boolean.Parse(ConfigurationManager.AppSettings["CacheEncryptionEnabled"])

The setting for CacheMaxAge to be -1 comes from threads in the support community as recommendation for "short lived" caching. If we set this to 1 day we see the same behaviour (documents not cleaned up).

Any suggestions why / how documents would not be cleaned up?

1 Reply

Reply to Thread
Cem Alacayir Replied
Employee Post Marked As Answer
-1 days was suggested for versions before 4.5.5 because after that version CacheMaxAge property is a TimeSpan. So you can specify it not only in days but in hours, minutes or seconds.

So you should use 0 for immediate expiration:

<add key="CacheMaxAge" value="0" />

The default value is 90 days. In string representation, value in format "d" is considered days (e.g. "30" is 30 days) and value in format "hh:mm" is considered hours and minutes (e.g. "1:30" is 1 hour and 30 minutes). Note that "24:00" would mean 24 days as hour range is 0 to 23 and minute range is 0 to 59. See Parse(String) documentation for details on possible string representations.
Also note that the last document that viewed is not removed from cache:

This is a designed behavior; last viewed document will not be removed from cache to prevent errors accessing the document simultaneously. If it’s removed to soon, the user currently viewing the document would have error when scrolling down because the document is loaded part by part (not whole file at once) However, when you view another document the previous one will be removed. So the cache should contain only 1 document at a time.

Reply to Thread