←Select platform

DocumentCacheInfo Class

Summary

Information about and properties of a document in the cache.

Syntax
C#
C++/CLI
Python
[SerializableAttribute()] 
[DataContractAttribute()] 
public class DocumentCacheInfo 
public: 
   [SerializableAttribute,  
   DataContractAttribute] 
   ref class DocumentCacheInfo 
class DocumentCacheInfo: 
Remarks

DocumentCacheInfo is returned by DocumentFactory.GetDocumentCacheInfo to quickly obtain information about a document in the cache without loading it. This includes whether the document is in the cache, its name and mime type, the number of pages, and whether it was loaded by the user.

This class contains the following members:

Member Description
DocumentId The unique ID of the document.
IsVirtual Indicates whether the document is virtual.
IsLoaded Indicates whether the document has been loaded at least once.
HasAnnotations Indicates whether the document has any annotations.
Name Document name
MimeType MIME type of the document
MimeTypeStatus Status of checking the document MIME type.
DocumentDataLength Length in bytes of the original document file, if any.
AnnotationsDataLength Length bytes of the original annotation file, if any.
PageCount Number of pages in this document.
HasUserToken Indicates that the document has an associated user token.
UserToken The user token associated with this document.
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 GetDocumentCacheInfoExample() 
{ 
   string documentFile = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"); 
 
   // Setup a cache 
   FileCache cache = new FileCache(); 
   cache.CacheDirectory = @"c:\cache-dir"; 
 
   // We will use this document ID 
   const string documentId = "test-document"; 
 
   // Ensure that the document does not exist in the cache 
   var deleteFromCacheOptions = new LoadFromCacheOptions(); 
   deleteFromCacheOptions.Cache = cache; 
   deleteFromCacheOptions.DocumentId = documentId; 
   DocumentFactory.DeleteFromCache(deleteFromCacheOptions); 
 
   DocumentCacheInfo cacheInfo; 
 
   // Now get the info for this document, it should not exist 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId); 
   Debug.Assert(cacheInfo == null); 
 
   // Next, upload a document into this cache 
   var uploadDocumentOptions = new UploadDocumentOptions(); 
   uploadDocumentOptions.Cache = cache; 
   uploadDocumentOptions.DocumentId = documentId; 
   uploadDocumentOptions.Name = "Leadtools.pdf"; 
   Uri uploadUri = DocumentFactory.BeginUpload(uploadDocumentOptions); 
   using (var stream = File.OpenRead(documentFile)) 
   { 
      var buffer = new byte[stream.Length]; 
      stream.Read(buffer, 0, buffer.Length); 
      DocumentFactory.UploadDocument(cache, uploadUri, buffer, 0, buffer.Length); 
   } 
   DocumentFactory.EndUpload(cache, uploadUri); 
 
   // Now check the info again, it should be there but not loaded 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId); 
   // DocumentCacheInfo reference 
   Console.WriteLine("After upload"); 
   Console.WriteLine("   DocumentId:" + cacheInfo.DocumentId); 
   Console.WriteLine("   Name:" + cacheInfo.Name); 
   Console.WriteLine("   IsLoaded:" + cacheInfo.IsLoaded); 
   Console.WriteLine("   Annotations data length:" + cacheInfo.AnnotationsDataLength); 
   Console.WriteLine("   Document data length:" + cacheInfo.DocumentDataLength); 
   Console.WriteLine("   Has annotations:" + cacheInfo.HasAnnotations); 
   Console.WriteLine("   Has user token:" + cacheInfo.HasUserToken); 
   Console.WriteLine("   Is virtual:" + cacheInfo.IsVirtual); 
   Console.WriteLine("   Mime Type:" + cacheInfo.MimeType); 
   Console.WriteLine("   Mime Type status:" + cacheInfo.MimeTypeStatus); 
   Console.WriteLine("   Page count:" + cacheInfo.PageCount); 
   Debug.Assert(cacheInfo.DocumentId == documentId); 
   Debug.Assert(cacheInfo.Name == "Leadtools.pdf"); 
   Debug.Assert(!cacheInfo.IsLoaded); 
   Debug.Assert(cacheInfo.AnnotationsDataLength == 0); 
   Debug.Assert(cacheInfo.DocumentDataLength == 90301); 
   Debug.Assert(!cacheInfo.HasAnnotations); 
   Debug.Assert(!cacheInfo.HasUserToken); 
   Debug.Assert(!cacheInfo.IsVirtual); 
   Debug.Assert(cacheInfo.MimeType == null); 
   Debug.Assert(cacheInfo.MimeTypeStatus == DocumentMimeTypeStatus.Unspecified); 
   Debug.Assert(cacheInfo.PageCount == 0); 
 
   // Next load this document 
   var loadDocumentOptions = new LoadDocumentOptions(); 
   loadDocumentOptions.Cache = cache; 
   using (var document = DocumentFactory.LoadFromUri(uploadUri, loadDocumentOptions)) 
   { 
      // Save it to the cache 
      document.AutoSaveToCache = false; 
      document.AutoDeleteFromCache = false; 
      document.SaveToCache(); 
   } 
 
   // Now get its info again, it should be there and loaded 
   cacheInfo = DocumentFactory.GetDocumentCacheInfo(cache, documentId); 
   Console.WriteLine("After load"); 
   Console.WriteLine("   DocumentId:" + cacheInfo.DocumentId); 
   Console.WriteLine("   Name:" + cacheInfo.Name); 
   Console.WriteLine("   IsLoaded:" + cacheInfo.IsLoaded); 
   Console.WriteLine("   Annotations data length:" + cacheInfo.AnnotationsDataLength); 
   Console.WriteLine("   Document data length:" + cacheInfo.DocumentDataLength); 
   Console.WriteLine("   Has annotations:" + cacheInfo.HasAnnotations); 
   Console.WriteLine("   Has user token:" + cacheInfo.HasUserToken); 
   Console.WriteLine("   Is virtual:" + cacheInfo.IsVirtual); 
   Console.WriteLine("   Mime Type:" + cacheInfo.MimeType); 
   Console.WriteLine("   Mime Type status:" + cacheInfo.MimeTypeStatus); 
   Console.WriteLine("   Page count:" + cacheInfo.PageCount); 
   Debug.Assert(cacheInfo.DocumentId == documentId); 
   Debug.Assert(cacheInfo.Name == "Leadtools.pdf"); 
   Debug.Assert(cacheInfo.IsLoaded); 
   Debug.Assert(cacheInfo.AnnotationsDataLength == 0); 
   Debug.Assert(cacheInfo.DocumentDataLength == 90301); 
   Debug.Assert(!cacheInfo.HasAnnotations); 
   Debug.Assert(!cacheInfo.HasUserToken); 
   Debug.Assert(!cacheInfo.IsVirtual); 
   Debug.Assert(cacheInfo.MimeType == "application/pdf"); 
   Debug.Assert(cacheInfo.MimeTypeStatus == DocumentMimeTypeStatus.Unspecified); 
   Debug.Assert(cacheInfo.PageCount == 5); 
} 
 
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 getDocumentCacheInfoExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String documentFile = combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"); 
 
   // Setup a cache 
   FileCache cache = new FileCache(); 
   cache.setCacheDirectory("c:\\cache-dir"); 
 
   // We will use this document ID 
   final String documentId = "test-document"; 
 
   // Ensure that the document does not exist in the cache 
   LoadFromCacheOptions deleteFromCacheOptions = new LoadFromCacheOptions(); 
   deleteFromCacheOptions.setCache(cache); 
   deleteFromCacheOptions.setDocumentId(documentId); 
   DocumentFactory.deleteFromCache(deleteFromCacheOptions); 
 
   DocumentCacheInfo cacheInfo; 
 
   // Now get the info for this document, it should not exist 
   cacheInfo = DocumentFactory.getDocumentCacheInfo(cache, documentId); 
   assertTrue(cacheInfo == null); 
 
   // Next, upload a document into this cache 
   UploadDocumentOptions uploadDocumentOptions = new UploadDocumentOptions(); 
   uploadDocumentOptions.setCache(cache); 
   uploadDocumentOptions.setDocumentId(documentId); 
   uploadDocumentOptions.setName("Leadtools.pdf"); 
   URI uploadUri = DocumentFactory.beginUpload(uploadDocumentOptions); 
   byte[] buffer = Files.readAllBytes(new File(documentFile).toPath()); 
   DocumentFactory.uploadDocument(cache, uploadUri, buffer, 0, buffer.length); 
   DocumentFactory.endUpload(cache, uploadUri); 
 
   // Now check the info again, it should be there but not loaded 
   cacheInfo = DocumentFactory.getDocumentCacheInfo(cache, documentId); 
   // DocumentCacheInfo reference 
   System.out.println("After upload"); 
   System.out.println("   DocumentId:" + cacheInfo.getDocumentId()); 
   System.out.println("   Name:" + cacheInfo.getName()); 
   System.out.println("   IsLoaded:" + cacheInfo.isLoaded()); 
   System.out.println("   Annotations data length:" + cacheInfo.getAnnotationsDataLength()); 
   System.out.println("   Document data length:" + cacheInfo.getDocumentDataLength()); 
   System.out.println("   Has annotations:" + cacheInfo.hasAnnotations()); 
   System.out.println("   Has user token:" + cacheInfo.hasUserToken()); 
   System.out.println("   Is virtual:" + cacheInfo.isVirtual()); 
   System.out.println("   Mime Type:" + cacheInfo.getMimeType()); 
   System.out.println("   Mime Type status:" + cacheInfo.getMimeTypeStatus()); 
   System.out.println("   Page count:" + cacheInfo.getPageCount()); 
   assertTrue(cacheInfo.getDocumentId().equals(documentId)); 
   System.out.println(cacheInfo.getName()); 
   assertTrue(cacheInfo.getName().equals("Leadtools.pdf")); 
   assertTrue(!cacheInfo.isLoaded()); 
   assertTrue(cacheInfo.getAnnotationsDataLength() == 0); 
   System.out.println(cacheInfo.getDocumentDataLength()); 
   assertTrue(cacheInfo.getDocumentDataLength() == 90301); 
   assertTrue(!cacheInfo.hasAnnotations()); 
   assertTrue(!cacheInfo.hasUserToken()); 
   assertTrue(!cacheInfo.isVirtual()); 
   assertTrue(cacheInfo.getMimeType() == null); 
   assertTrue(cacheInfo.getMimeTypeStatus() == DocumentMimeTypeStatus.UNSPECIFIED); 
   assertTrue(cacheInfo.getPageCount() == 0); 
 
   // Next load this document 
   LoadDocumentOptions loadDocumentOptions = new LoadDocumentOptions(); 
   loadDocumentOptions.setCache(cache); 
   LEADDocument document = DocumentFactory.loadFromUri(uploadUri, loadDocumentOptions); 
   // Save it to the cache 
   document.setAutoSaveToCache(false); 
   document.setAutoDeleteFromCache(false); 
   document.saveToCache(); 
 
   // Now get its info again, it should be there and loaded 
   cacheInfo = DocumentFactory.getDocumentCacheInfo(cache, documentId); 
   System.out.println("After load"); 
   System.out.println("   DocumentId:" + cacheInfo.getDocumentId()); 
   System.out.println("   Name:" + cacheInfo.getName()); 
   System.out.println("   IsLoaded:" + cacheInfo.isLoaded()); 
   System.out.println("   Annotations data length:" + cacheInfo.getAnnotationsDataLength()); 
   System.out.println("   Document data length:" + cacheInfo.getDocumentDataLength()); 
   System.out.println("   Has annotations:" + cacheInfo.hasAnnotations()); 
   System.out.println("   Has user token:" + cacheInfo.hasUserToken()); 
   System.out.println("   Is virtual:" + cacheInfo.isVirtual()); 
   System.out.println("   Mime Type:" + cacheInfo.getMimeType()); 
   System.out.println("   Mime Type status:" + cacheInfo.getMimeTypeStatus()); 
   System.out.println("   Page count:" + cacheInfo.getPageCount()); 
   assertTrue(cacheInfo.getDocumentId().equals(documentId)); 
   assertTrue(cacheInfo.getName().equals("Leadtools.pdf")); 
   assertTrue(cacheInfo.isLoaded()); 
   assertTrue(cacheInfo.getAnnotationsDataLength() == 0); 
   assertTrue(cacheInfo.getDocumentDataLength() == 90301); 
   assertTrue(!cacheInfo.hasAnnotations()); 
   assertTrue(!cacheInfo.hasUserToken()); 
   assertTrue(!cacheInfo.isVirtual()); 
   assertTrue(cacheInfo.getMimeType().equals("application/pdf")); 
   assertTrue(cacheInfo.getMimeTypeStatus() == DocumentMimeTypeStatus.UNSPECIFIED); 
   assertTrue(cacheInfo.getPageCount() == 5); 
} 
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.