loadFromCache Method

Summary

Retrieves the document matching the given documentId string from the cache.

Syntax
TypeScript
JavaScript
loadFromCache = function( 
   documentId 
) 
static loadFromCache( 
   documentId: string 
): JQueryPromise<LEADDocument>; 

Parameters

documentId

documentId from a previously cached LEADDocument object.

Return Value

A Promise object that may resolve successfully to a LEADDocument object, or fail if the LEADDocument cannot be returned because it does not exist with that documentId.

Remarks

This static method will return a LEADDocument object that is known to already exist in the cache from being loaded via LoadFromUri or uploaded via UploadFile or UploadDocument.

LoadFromCache is meant as a quick version of LoadFromUri and does not take a LoadDocumentOptions object.

If DeleteFromCache is called on the LEADDocument or the cache time has expired for the object, it will not be available via this method.

Documents can be manually deleted from the cache at any time using DeleteFromCache.

Example

This example will load a document from a uri, then show that it can be re-loaded from the cache. After successfully loading from the cache, the document is explicitly deleted from the cache.

Start with the example from LEADDocument and replace all the code inside the example function (search for the "// TODO: add example code here" comment) with the following code:

TypeScript
JavaScript
var url = "https://demo.leadtools.com/images/pdf/leadtools.pdf"; 
var loadDocumentOptions = new lt.Document.LoadDocumentOptions(); 
lt.Document.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
   .done(function (doc) { 
      log("Document loaded from url", doc); 
      // Get the ID and get rid of the document 
      var documentId = doc.documentId; 
      doc.dispose(); 
 
      // Now, re-load it from the cache using its document ID 
      lt.Document.DocumentFactory.loadFromCache(documentId) 
         .done(function (doc) { 
            log("Document loaded from cache", doc); 
 
            // Now, delete it from the cache 
            lt.Document.DocumentFactory.deleteFromCache(documentId) 
               .done(function () { 
                  log("Deleted from cache - next load from cache should fail..."); 
                  lt.Document.DocumentFactory.loadFromCache(documentId) 
                     .done(function (doc) { 
                        // doc must be null here 
                        if (!doc) { 
                           log("Document was not found in cache (success)"); 
                        } 
                        else { 
                           throw new Error("Something went wrong!"); 
                        } 
                     }) 
                     .fail(showServiceError); 
               }) 
               .fail(showServiceError); 
         }) 
         .fail(showServiceError); 
   }) 
   .fail(showServiceError); 
class DocumentFactory_LoadFromCacheExample { 
    public constructor() { 
        lt.RasterSupport.setLicenseUri("https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt", "EVAL", null); 
    } 
 
    public run(buttonID: string) { 
        document.getElementById(buttonID).onclick = this.loadFromCache; 
    } 
 
    /** 
     * Load a new document from URI 
     */ 
    loadFromCache = () => { 
        const url = "https://demo.leadtools.com/images/pdf/leadtools.pdf"; 
        const loadDocumentOptions = new lt.Document.LoadDocumentOptions(); 
 
        lt.Document.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
            .done((document: lt.Document.LEADDocument) => { 
                log("Document loaded from url", document); 
 
                // Get the ID and get rid of the document 
                const documentId = document.documentId; 
                document.dispose(); 
 
                // Now, re-load it from the cache using its document ID 
                lt.Document.DocumentFactory.loadFromCache(documentId) 
                    .done((document: lt.Document.LEADDocument) =>{ 
                        log("Document loaded from cache", document); 
 
                        // Now, delete it from the cache 
                        lt.Document.DocumentFactory.deleteFromCache(documentId) 
                            .done(() => { 
                                log("Deleted from cache - next load from cache should fail..."); 
                                lt.Document.DocumentFactory.loadFromCache(documentId) 
                                    .done((document: lt.Document.LEADDocument)=>{ 
                                        // doc must be null here 
                                        if (!document) { 
                                            log("Document was not found in cache (success)"); 
                                        } 
                                        else { 
                                            throw new Error("Something went wrong!"); 
                                        } 
                                    }) 
                                    .fail(showServiceError); 
                            }) 
                            .fail(showServiceError); 
                    }) 
                    .fail(showServiceError); 
 
            }) 
            .fail(showServiceError); 
    } 
} 

Requirements

Target Platforms

Help Version 20.0.2019.4.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly