loadFromCache Method

Summary

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

Syntax

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

Parameters

documentId

documentId from a previously cached Document object.

Return Value

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

Remarks

This static method will return a Document 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 Document 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 then delete it from the cache.

Start with the example in Document and replace the example function call to the function below.

JavaScript Example
function loadFromCacheExample() { 
   // Load a new document 
   var url = "https://demo.leadtools.com/images/pdf/leadtools.pdf"; 
   var loadDocumentOptions = new lt.Documents.LoadDocumentOptions(); 
   lt.Documents.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
       .done(function (doc) { 
          console.log("Document was loaded succesfully from URI"); 
          // Get the ID and get rid of the document 
          var documentId = doc.documentId; 
          doc.dispose(); 
          doc = null; 
          // Now, re-load it from the cache using its document ID 
          lt.Documents.DocumentFactory.loadFromCache(documentId) 
              .done(function (doc) { 
                 console.log("Document was loaded succesfully from cache"); 
                 // Delete it from the cache 
                 lt.Documents.DocumentFactory.deleteFromCache(documentId) 
                     .done(function () { 
                        console.log("Deleted from cache, try to load it again from cache..."); 
                        lt.Documents.DocumentFactory.loadFromCache(documentId) 
                            .done(function (doc) { 
                               // doc must be null here 
                               if (doc == null) { 
                                  console.log("Document was not found in cache"); 
                               } 
                               else { 
                                  throw "Something went wrong"; 
                               } 
                            }) 
                            .fail(function (jqXHR, statusText, errorThrown) { 
                               showServiceError(jqXHR, statusText, errorThrown); 
                            }); 
                     }) 
                     .fail(function (jqXHR, statusText, errorThrown) { 
                        showServiceError(jqXHR, statusText, errorThrown); 
                     }); 
              }) 
              .fail(function (jqXHR, statusText, errorThrown) { 
                 showServiceError(jqXHR, statusText, errorThrown); 
              }); 
       }) 
       .fail(function (jqXHR, statusText, errorThrown) { 
          showServiceError(jqXHR, statusText, errorThrown); 
       }); 
} 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Documents Assembly