←Select platform

IsDocumentInCache Method

Summary

Helper method to quickly determine if a document exists in the cache.

Syntax
C#
VB
C++
public static bool IsDocumentInCache( 
   ObjectCache cache, 
   string documentId 
) 
Public Shared Function IsDocumentInCache( 
   ByVal cache As ObjectCache, 
   ByVal documentId As String 
) As Boolean 
public:  
   static bool IsDocumentInCache( 
      ObjectCache^ cache, 
      String^ documentId 
   ) 

Parameters

cache

Cache to check. This value cannot be null.

documentId

The ID of the document to check. This value cannot be null and can be either a document ID or the URL to an uploaded LEAD document (leaddocument://).

Return Value

true if the document exists in the cache; otherwise, false.

Remarks

This method uses the information described in Document Toolkit and Caching to quickly determine if the document exists in the cache.

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
public static void IsDocumentInCacheExample() 
{ 
   // Create a cache 
   FileCache cache = new FileCache(); 
   cache.CacheDirectory = @"c:\cache-dir"; 
 
   // We will use a custom document ID 
   string documentId = "my-document"; 
 
   // Ensure the document is not in the cache 
   Debug.Assert(!DocumentFactory.IsDocumentInCache(cache, documentId)); 
 
   // Upload the into the document 
   Uri documentUri = DocumentFactory.BeginUpload(new UploadDocumentOptions 
   { 
      Cache = cache, 
      DocumentId = documentId, 
   }); 
 
   byte[] data = System.IO.File.ReadAllBytes(@"C:\users\Public\Documents\LEADTOOLS Images\leadtools.pdf"); 
   DocumentFactory.UploadDocument(cache, documentUri, data, 0, data.Length); 
   DocumentFactory.EndUpload(cache, documentUri); 
 
   // Now ensure the document is in the cache, using the ID and the URI 
   Debug.Assert(DocumentFactory.IsDocumentInCache(cache, documentId)); 
   Debug.Assert(DocumentFactory.IsDocumentInCache(cache, documentUri.ToString())); 
 
   // Load the document from the cache 
   using (LEADDocument document = DocumentFactory.LoadFromUri(documentUri, 
      new LoadDocumentOptions 
      { 
         Cache = cache, 
      })) 
   { 
      Debug.Assert(document != null); 
      document.AutoDeleteFromCache = false; 
      document.AutoSaveToCache = false; 
      document.SaveToCache(); 
   } 
 
   // Ensure the document is still in the cache, using the ID and the URI 
   Debug.Assert(DocumentFactory.IsDocumentInCache(cache, documentId)); 
   Debug.Assert(DocumentFactory.IsDocumentInCache(cache, documentUri.ToString())); 
 
   // Delete the document from the cache 
   bool isDeleted = DocumentFactory.DeleteFromCache(new LoadFromCacheOptions 
   { 
      Cache = cache, 
      DocumentId = documentId 
   }); 
   Debug.Assert(isDeleted); 
 
   // Ensure the document is not in the cache 
   Debug.Assert(!DocumentFactory.IsDocumentInCache(cache, documentId)); 
   Debug.Assert(!DocumentFactory.IsDocumentInCache(cache, documentUri.ToString())); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Document.Writer 
Imports Leadtools.Svg 
Imports Leadtools.Document 
Imports Leadtools.Caching 
Imports Leadtools.Annotations.Engine 
Imports Leadtools.Barcode 
Imports Leadtools.Ocr 
Imports LeadtoolsDocumentExamples.LeadtoolsExamples.Common 
Imports Leadtools.Document.Converter 
 
Public Shared Sub IsDocumentInCacheExample() 
   ' Create a cache 
   Dim cache As New FileCache() 
   cache.CacheDirectory = "c:\cache-dir" 
 
   ' We will use a custom document ID 
   Dim documentId As String = "my-document" 
 
   ' Ensure the document Is Not in the cache 
   Debug.Assert(Not DocumentFactory.IsDocumentInCache(cache, documentId)) 
 
   ' Upload the into the document 
   Dim documentUri As Uri = DocumentFactory.BeginUpload(New UploadDocumentOptions With 
   { 
      .Cache = cache, 
      .DocumentId = documentId 
   }) 
 
   Dim data() As Byte = System.IO.File.ReadAllBytes("C:\users\Public\Documents\LEADTOOLS Images\leadtools.pdf") 
   DocumentFactory.UploadDocument(cache, documentUri, data, 0, data.Length) 
   DocumentFactory.EndUpload(cache, documentUri) 
 
   ' Now ensure the document Is in the cache, using the ID And the URI 
   Debug.Assert(DocumentFactory.IsDocumentInCache(cache, documentId)) 
   Debug.Assert(DocumentFactory.IsDocumentInCache(cache, documentUri.ToString())) 
 
   ' Load the document from the cache 
   Using document As LEADDocument = DocumentFactory.LoadFromUri(documentUri, 
      New LoadDocumentOptions With 
      { 
         .Cache = cache 
      }) 
      Debug.Assert(Not IsNothing(document)) 
      document.AutoDeleteFromCache = False 
      document.AutoSaveToCache = False 
      document.SaveToCache() 
   End Using 
 
   ' Ensure the document Is still in the cache, using the ID And the URI 
   Debug.Assert(DocumentFactory.IsDocumentInCache(cache, documentId)) 
   Debug.Assert(DocumentFactory.IsDocumentInCache(cache, documentUri.ToString())) 
 
   ' Delete the document from the cache 
   Dim isDeleted As Boolean = DocumentFactory.DeleteFromCache(New LoadFromCacheOptions With 
   { 
      .Cache = cache, 
      .DocumentId = documentId 
   }) 
   Debug.Assert(isDeleted) 
 
   ' Ensure the document Is Not in the cache 
   Debug.Assert(Not DocumentFactory.IsDocumentInCache(cache, documentId)) 
   Debug.Assert(Not DocumentFactory.IsDocumentInCache(cache, documentUri.ToString())) 
End Sub 

Requirements

Target Platforms

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

Leadtools.Document Assembly