←Select platform

LoadFromCache(string) Method

Summary

Loads a previously saved document from the global cache.

Syntax
C#
C++/CLI
Java
Python
[ObsoleteAttribute("User LoadFromCache(LoadFromCacheOptions) instead")] 
public static LEADDocument LoadFromCache( 
   string documentId 
) 
public:  
   static LEADDocument^ LoadFromCache( 
      String^ documentId 
   ) 
public static Document loadFromCache(String documentId) 
def LoadFromCache(self,documentId): 

Parameters

documentId

The document identifier. This value cannot be null.

Return Value

The document object if found in the cache; otherwise, null.

Remarks

Note: This method will be deprecated in the next version of LEADTOOLS, use LoadFromCache(LoadFromCacheOptions) instead.

This method is the equivalent of calling LoadFromCache(DocumentFactory.Cache, documentId) and therefore will throw an exception if Cache was not setup.

Use this method to load a document previously stored in the cache with SaveToCache. The document will be re-loaded and populated exactly as it was during the time it was saved. If the document was originally created by using LoadFromFile then the original file must still exist and can be accessed. If the document was originally created by using LoadFromUri, LoadFromUriAsync or Create, then the library had copied the original file into the cache and is no longer used. The document can be re-constructed even if the original file is deleted.

If this document was originally created by using LoadFromStream, then the data stored in the stream was saved into the cache during SaveToCache and the stream is no longer used and loading this document will act in the same manner as if it was downloaded from an external URI.

This method may return null if the document was in the cache but it is expired and purged.

Saving and loading from the cache is useful if the document is to be re-used between sessions in your application. The document identifier (documentId) is all you need to store to re-construct the document after it was saved to the cache and disposed. This ID can be stored in a database or passed to the client side as in the case of the LEADTOOLS Document Web Service.

LoadFromCache supports loading a document that has been uploaded and not loaded yet. The factory will check and performs a call to LoadFromUri internally.

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

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
 
public void DocumentIdExample() 
{ 
   var cache = GetCache(); 
 
   var policy = new CacheItemPolicy(); 
   policy.AbsoluteExpiration = DateTime.Now + new TimeSpan(0, 0, 10); 
   policy.SlidingExpiration = new TimeSpan(0, 0, 10); 
 
   var options = new LoadDocumentOptions(); 
   options.Cache = cache; 
   options.CachePolicy = policy; 
 
   string documentId = null; 
 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"), options)) 
   { 
      document.AutoDeleteFromCache = false; 
      documentId = document.DocumentId; 
      document.SaveToCache(); 
   } 
 
   var loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.Cache = cache; 
   loadFromCacheOptions.DocumentId = documentId; 
   using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)) 
   { 
      if (null != document) 
      { 
         document.AutoDeleteFromCache = true;//will be deleted 
      } 
   } 
} 
 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.net.URL; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.util.ArrayList; 
import java.util.Calendar; 
import java.util.List; 
import java.util.concurrent.Callable; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
import java.util.concurrent.Future; 
import java.util.regex.Pattern; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.annotations.engine.*; 
import leadtools.barcode.*; 
import leadtools.caching.*; 
import leadtools.codecs.*; 
import leadtools.document.*; 
import leadtools.document.DocumentMimeTypes.UserGetDocumentStatusHandler; 
import leadtools.document.converter.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void documentIdExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   FileCache cache = getCache(); 
 
   CacheItemPolicy policy = new CacheItemPolicy(); 
   Calendar calendar = Calendar.getInstance(); 
   calendar.add(Calendar.SECOND, 10); 
   policy.setAbsoluteExpiration(calendar.getTime()); 
   policy.setSlidingExpiration(10); 
 
   LoadDocumentOptions options = new LoadDocumentOptions(); 
   options.setCache(cache); 
   options.setCachePolicy(policy); 
 
   String documentId = null; 
 
   LEADDocument document = DocumentFactory.loadFromFile(combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"), options); 
 
   document.setAutoDeleteFromCache(false); 
   documentId = document.getDocumentId(); 
   document.saveToCache(); 
 
   LoadFromCacheOptions loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.setCache(cache); 
   loadFromCacheOptions.setDocumentId(documentId); 
   document = DocumentFactory.loadFromCache(loadFromCacheOptions); 
   if (null != document) { 
      document.setAutoDeleteFromCache(true);// will be deleted 
   } 
} 
Requirements

Target Platforms

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

Leadtools.Document Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.