DocumentCache Class
Definition
- Namespace
- GleamTech.DocumentUltimate.Caching
- Assembly
- GleamTech.DocumentUltimate.dll
Provides methods for handling caching of documents.
public class DocumentCache : FileCache
- Inheritance
-
FileCacheDocumentCache
Examples
Accessing document cache in the same web application which uses DocumentViewer:
//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();
'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.
Dim documentCache = DocumentUltimateWebConfiguration.Current.GetCache()
Accessing document cache in other applications:
/*
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");
' 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.
Dim documentCache = New DocumentCache("C:\SomeFolder\DocumentCache")
Pre-caching:
/*
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"
}
}
}
);
'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() With {
.Watermarks = New Collection(Of Watermark) From {
new TextWatermark With {
.Text = "Sample watermark"
}
}
})
Constructors
| DocumentCache(Location, bool, DocumentUltimateConfiguration) |
Initializes a new instance of the DocumentCache class. |
Properties
| 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. |
Methods
| CreateCacheInfo(FileProvider, DocumentCacheOptions) |
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. |
| GetOrAddPdf(DocumentCacheInfo, string) |
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. |
| LoadCacheInfo(FileCacheKey, bool, bool) |
Loads the cache info for a document that was saved before, from the actual cache. |
| OnMigrate(Version) |
Implement this method in a subclass to return migrations ro execute for its specific cache files. |
| PreCacheDocument(FileProvider, DocumentCacheOptions) |
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. |
| SaveCacheInfo(DocumentCacheInfo) |
Saves the cache info for a document, to the actual cache. |