1
Disable cache for a document
Question asked by Ciprian Raduelscu - July 31 at 7:05 AM
Answered
Hello,
 
In our system we have a scenario when you keep generating the same PDF but with different data. The unique ID for the document doesn't change though so the PDF served to the client is the same as the first time it was generated. Is there anyway to either prevent a document from being cached or just delete it from the cache before generating it the 2nd time?
 
Thanks

1 Reply

Reply to Thread
0
Cem Alacayir Replied
August 1 at 12:06 PM
Employee Post
If your PDF is generated with different data then it's a different PDF. The point of uniqueID is to identify a binary version of document.
 
uniqueId
Type: System.String
The unique identifier that will be used for generating the cache key for this document. For instance, it can be an ID from your database table or a simple file name; you just need to make sure this ID varies for each different document so that they are cached correctly. For example for files on disk, we internally use a string combination of file extension, file size and file date for uniquely identifying them, this way cache collisions do not occur and we can resuse the cached file even if the file name before extension is changed (because it's still the same document).
So you need to vary your uniqueID, otherwise same cache key will be generated and already cached version will be loaded. As you would notice uniqueID is a string so you can vary it as you would like, e.g. append a version number or DateTime.Now.Ticks.
 
Regarding cache lifetime of a file:
 
CacheMaxDays
Gets or sets the maximum number of days to store cached documents. The default value is 90 days.
For example if you set 
DocumentUltimateWebConfiguration.Current.CacheMaxDays = -1;
Then a cache file would immediately expire and when next request comes it would be deleted.
So if your generated PDF files are short-lived you can use this setting to prevent keeping all versions of the PDF file cached.

Reply to Thread