Click or drag to resize

Pre-caching documents

Normally the source document is converted to a special web-friendly format and cached after the document viewer is displayed in the page and when the document is viewed for the first time. With DocumentCache.PreCacheDocument 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 return without doing anything:

  • Pre-caching in the same web application which uses DocumentViewer:

    var documentCache = DocumentUltimateWebConfiguration.Current.GetCache();
    
    documentCache.PreCacheDocument(
        new DocumentOptions
        {
            Document = @"C:\some\document.pdf"
        }
    );

    This DocumentCache instance is already filled with necessary information like cache path, license key etc.

  • Pre-caching in other applications:

    DocumentUltimateConfiguration.Current.LicenseKey = "QQJDJLJP34...";
    
    var documentCache = new DocumentCache(@"C:\some\cache\folder");
    
    documentCache.PreCacheDocument(
        new DocumentOptions
        {
            Document = @"C:\some\document.pdf"
        }
    );

    When you do the precaching outside the web application that uses DocumentUltimate, e.g. inside a Console application, make sure;

    • You set your license key in that application before calling PreCacheDocument method. Or you can create a DocumentUltimateConfiguration instance with your license key and pass that instance to the DocumentCache constructor.

    • You pass parameters (path, maxDays, encryptionEnabled) 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 path parameter unless you change default values of other parameters. Note that DocumentUltimateWebConfiguration.Current.CachePath accepts also virtual paths but when passing path parameter to DocumentCache constructor, use the physical path (resolved path) because in a non-web application virtual paths can not be resolved.