←Select platform

SaveToCache Method

Summary

Saves the document to the cache.

Syntax
C#
C++/CLI
Java
Python
public void SaveToCache() 
public:  
   void SaveToCache() 
public void saveToCache() 
def SaveToCache(self): 
Remarks

Documents can contain many pages and huge amounts of data. Storing all this data in the physical memory is not feasible in most situations. Therefore, the LEADDocument class was designed to use an external caching system to store the modified document. Refer to DocumentFactory.Cache for more information.

HasCache determines if this document is using the cache system. SaveToCache can be used to save a document to the cache and re-load it with DocumentFactory.LoadFromCache.

Set AutoDeleteFromCache to true if your application uses caching to speed up processing the document and the object will not be used after it is disposed.

Set AutoDeleteFromCache to false if your application will save the document ID before disposing the document, and use it to re-load the document by calling DocumentFactory.LoadFromCache.

To save the document to the cache, call SaveToCache or set the value of AutoSaveToCache to true before disposing the document.

The document is only saved into the cache if the value of CacheStatus is DocumentCacheStatus.NotSynced. When SaveToCache returns successfully, the value of CacheStatus of the document will be DocumentCacheStatus and will contain the timestamp of the operation.

Refer to Document Toolkit and Caching for more information.

Example
C#
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:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

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