←Select platform

Cache Property


The LEADTOOLS ObjectCache object responsible for managing cache items and expiration policies.


public static ObjectCache Cache { get; set; } 
Public Shared Property Cache() As ObjectCache 
   static property ObjectCache^ Cache 
      ObjectCache^ get() 
      void set(ObjectCache^ value) 
public static ObjectCache getCache() 
public void sbjectCache getCache(static value) 

Property Value

The cache object responsible for managing cache items and expiration policies. Default value is null.


A large portion of the Documents class library requires the use of a cache system. This includes almost all of the write support. Documents can contain large number of pages and huge amount of data. Storing all this data in the physical memory is not feasible in most situations. Therefore, the Documents library was designed to use an external caching system to store the modified parts of the document.

Using a large will also increase the performance when getting page data such as an image or text. The result will be parsed once from the physical file on disk, processed and then stored in the cache. Subsequent calls to the same data will simply retrieve it from the cache without any extra processing.

The LEADTOOLS Documents Web Service requires the use of a cache. Web methods are sessionless by nature and with cache support, the service can use SaveToCache and LoadFromCache to save/load the document state in between calls without the need for session state. DeleteFromCache can be used to remove a document form the cache when it is no longer needed.

In almost all cases, the cache object is initialized and set into Cache at the start of the application and then never touched. The DocumentFactory and Document classes will use this global value for all the caching needs.

The default LEADTOOLS implementation of ObjectCache is FileCache object and setting it up is easy. The only input required is the path to a directory on disk or network share where the cache items are stored.

Refer to Document Toolkit and Caching for more information on how the cache is used with the LEADTOOLS Documents library and how to set up optional custom cache provider.

Generally, the cache is used in two ways depending on the type of the application:

  • The application uses the cache to speed up getting data from existing documents or to create new documents. The data is not shared with other applications nor is required to persist between sessions. One such example is the LEADTOOLS Document Viewer Demo. It obtains a temporary folder and set it as the cache directory to use (CacheDirectory objects that do not expire and the document parts are cached and used. The value of AutoSaveToCache is set to false and each document will delete its cache entry when it is disposed and no longer used.

  • The application requires the document state to persist between sessions. One such example is the LEADTOOLS Documents Web Service. It contains a global cache directory stored in the web.config file. The cache is constructed with each session (web method) by setting the same value in CacheDirectory. When a document is loaded, it is saved in the cache using SaveToCache before the web method returns and then re-loaded when a new session (web method) starts using LoadFromCache. These types of applications usually store a policy setting in the web.config as well. This will control how long to store items in the cache before they expire. The FileCache.CheckPolicies method can be used by an external process in the application to periodically run and purge expired items.


For an example, refer to DocumentFactory


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