DocumentCache Class

Provides methods for handling caching of documents.

Definition

Namespace: GleamTech.DocumentUltimate.Caching
Assembly: GleamTech.DocumentUltimate (in GleamTech.DocumentUltimate.dll) Version: 6.9.8
C#
public class DocumentCache : FileCache
Inheritance
Object    FileCache    DocumentCache

Example

Accessing document cache in the same web application which uses DocumentViewer:

C#
//This DocumentCache instance is already filled with necessary information like cache location, license key etc.
//So it will use the same settings as the DocumentViewer.
var documentCache = DocumentUltimateWebConfiguration.Current.GetCache();

Accessing document cache in other applications:

C#
/*
Make sure you set your license key in external application before calling PreCacheDocument method.
Or you can create a DocumentUltimateConfiguration instance with your license key and pass that
instance to the DocumentCache constructor.
*/
DocumentUltimateConfiguration.Current.LicenseKey = "QQJDJLJP34...";

/*
Make sure you pass parameters (location, encryptionEnabled, keepVariations) to DocumentCache constructor
which are the same values that are set in DocumentUltimateWebConfiguration.Current in your web application 
that hosts the DocumentViewer. Usually you would only need to pass location parameter unless you 
change default values of other parameters.

Note that DocumentUltimateWebConfiguration.Current.CacheLocation accepts also virtual paths (e.g. "~/App_Data/DocumentCache")
but in a non-web application e.g. in a Console application, when passing location parameter to DocumentCache constructor, 
use the physical path (resolved path) because virtual paths can not be resolved in a non-web application.
*/
var documentCache = new DocumentCache(@"C:\SomeFolder\DocumentCache");

Pre-caching:

C#
/*
Pass the document (FileProvider) to PreCacheDocument method which is the same that will passed to DocumentViewer.
CacheSourceKey is generated according to combination of file extension, file modified date and file size info.

Note that DocumentViewer.Document accepts also virtual paths (e.g. "~/SomeFolder/Document.docx")
but in a non-web application e.g. in a Console application, when passing document parameter to PreCacheDocument method,
use the physical path (resolved path) because virtual paths can not be resolved in a non-web application.
*/
documentCache.PreCacheDocument(@"c:\SomeFolder\Document.docx");


//Pass the same document options that will be set in DocumentViewer.DocumentOptions.
//This is because some options can change CachePdfKey and/or CacheXpzKey.
documentCache.PreCacheDocument(
    @"c:\SomeFolder\Document.docx",
    new DocumentOptions
    {
        Watermarks = new Collection<Watermark>
        {
            new TextWatermark
            {
                Text = "Sample watermark"
            }
        }
    }
);

Constructors

DocumentCache Initializes a new instance of the DocumentCache class.

Properties

AutoTrimInterval Gets or sets a value that specifies the interval to run automatic cache trimming (clean up). Cached items older than MaxAge will be removed when the cache is trimmed. If the value is 0 or negative, the auto trim is disabled. The default value is 20 minutes.
(Inherited from FileCache)
EncryptionEnabled Gets a value that specifies whether encryption of documents should be enabled. The default is true.

Document viewer downloads a special document format (XPZ) on the client-side but for additional security (DRM), the document is also encrypted by default.

Note that changes in this property change CacheXpzKey.

KeepVariations Gets a value that specifies whether to keep variations of document conversion results. The default is false.

For instance when you change watermark options, both Pdf and Xpz outputs are regenerated. By default the Pdf and Xpz outputs are replaced in cache when watermarks are changed. If you set this property to true, the Pdf and Xpz outputs will not be replaced but all variations will be kept in cache instead. This can be useful especially when you want different outputs for different users. So this way, for instance you can have different watermarked variations for each different user.

LocationId Gets the unique identifier for the location to store cached files.
(Inherited from FileCache)
LocationString Gets the string representation of location to store cached files.
(Inherited from FileCache)
MaxAge Gets or sets a value that specifies the maximum amount of time to consider a cached item fresh and keep it stored in the cache. Cached items older than this age will be removed when the cache trimming (clean up) runs (when auto trim is run or when Trim is manually called). The default value is 90 days.
(Inherited from FileCache)
WaitTimeout Gets or sets a value that specifies the maximum amount of time to wait for a cached item to be available (wait for a file lock from other threads or processes to become available, i.e. wait for an ongoing caching of the same file to complete) before giving up on the cache request. The default value is 5 minutes.
(Inherited from FileCache)

Methods

AddOrUpdate
(Inherited from FileCache)
Contains
(Inherited from FileCache)
CreateCacheInfo Creates the cache info for a document. This method can be used if you need to know the cache keys beforehand without calling PreCacheDocument(FileProvider, DocumentCacheOptions) method.
Get
(Inherited from FileCache)
GetOrAdd
(Inherited from FileCache)
GetOrAddPdf Gets or adds the PDF cache file. This method handles the first step of the conversion: Source -> PDF.

Normally you would not need to call this method directly because calling only PreCacheDocument(FileProvider, DocumentCacheOptions) method handles the conversion chain: Source -> PDF -> XPZ.

GetOrAddXpz Gets or adds the XPZ cache file. This method handles the second step of the conversion: PDF -> XPZ.

Normally you would not need to call this method directly because calling only PreCacheDocument(FileProvider, DocumentCacheOptions) method handles the conversion chain: Source -> PDF -> XPZ.

LoadCacheInfoLoads the cache info for a document that was saved before, from the actual cache.
LogEvent
(Inherited from FileCache)
LogGlobalEvent
(Inherited from FileCache)
OnMigrate Implement this method in a subclass to return migrations ro execute for its specific cache files.
(Overrides FileCache.OnMigrate(Version))
PreCacheDocument Pre-caches a document that may be loaded and displayed in the document viewer later.

Normally the source document is converted to a special web-friendly format (XPZ) and cached after the document viewer is displayed in the page and when the document is viewed for the first time. With this method, you can do the conversion and caching beforehand so this way, when a user opens the document for the first time, there will be no waiting and the document will be loaded immediately from the cache. If the source document is already converted and cached, then this method will do nothing and return the existing cached item.

Remove
(Inherited from FileCache)
SaveCacheInfoSaves the cache info for a document, to the actual cache.
Trim Trims the cache (cleans up the expired cache items, i.e. cached items older than MaxAge).
(Inherited from FileCache)

See Also