Retrieves information for a document in the cache using its ID.
public static DocumentCacheInfo GetDocumentCacheInfo(
ObjectCache cache,
string documentId
)
Public Shared Function GetDocumentCacheInfo(
ByVal cache As ObjectCache,
ByVal documentId As String
) As DocumentCacheInfo
public:
static DocumentCacheInfo^ GetDocumentCacheInfo(
ObjectCache^ cache,
String^ documentId
)
cache
The cache object to use. This value cannot be null.
documentId
The document identifier. This value cannot be null.
DocumentCacheInfo object that contains the information of the document referenced by documentId such as its name, mime type, page count if the document was found in the cache; otherwise, null if no document with the ID specified by documentId was found in the cache.
Use GetDocumentCacheInfo to quickly obtain information on 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 example shows how to use GetDocumentCacheInfo to get information on a document in the cache in various stages.
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 GetDocumentCacheInfoExample()
{
string documentFile = Path.Combine(ImagesPath.Path, "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);
Console.WriteLine("After upload");
Console.WriteLine(" DocumentId:" + cacheInfo.DocumentId);
Console.WriteLine(" Name:" + cacheInfo.Name);
Console.WriteLine(" IsLoaded:" + cacheInfo.IsLoaded);
Debug.Assert(cacheInfo.DocumentId == documentId);
Debug.Assert(cacheInfo.Name == "Leadtools.pdf");
Debug.Assert(!cacheInfo.IsLoaded);
// 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);
Debug.Assert(cacheInfo.DocumentId == documentId);
Debug.Assert(cacheInfo.Name == "Leadtools.pdf");
Debug.Assert(cacheInfo.IsLoaded);
}
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 GetDocumentCacheInfoExample()
Dim documentFile As String = Path.Combine(ImagesPath.Path, "Leadtools.pdf")
' Setup a cache
Dim Cache As New FileCache()
Cache.CacheDirectory = "c:\cache-dir"
' We will use this document ID
Const documentId As String = "test-document"
' Ensure that the document does Not exist in the cache
Dim deleteFromCacheOptions As New LoadFromCacheOptions
deleteFromCacheOptions.Cache = Cache
deleteFromCacheOptions.DocumentId = documentId
DocumentFactory.DeleteFromCache(deleteFromCacheOptions)
Dim cacheInfo As DocumentCacheInfo
' Now get the info for this document, it should Not exist
cacheInfo = DocumentFactory.GetDocumentCacheInfo(Cache, documentId)
Debug.Assert(IsNothing(cacheInfo))
' Next, upload a document into this cache
Dim UploadDocumentOptions As New UploadDocumentOptions()
UploadDocumentOptions.Cache = Cache
UploadDocumentOptions.DocumentId = documentId
UploadDocumentOptions.Name = "Leadtools.pdf"
Dim uploadUri As Uri = DocumentFactory.BeginUpload(UploadDocumentOptions)
Using stream As Stream = File.OpenRead(documentFile)
Dim buffer(CType(stream.Length - 1, Integer)) As Byte
stream.Read(buffer, 0, buffer.Length)
DocumentFactory.UploadDocument(Cache, uploadUri, buffer, 0, buffer.Length)
End Using
DocumentFactory.EndUpload(Cache, uploadUri)
' Now check the info again, it should be there but Not loaded
cacheInfo = DocumentFactory.GetDocumentCacheInfo(Cache, documentId)
Console.WriteLine("After upload")
Console.WriteLine(" DocumentId:" + cacheInfo.DocumentId)
Console.WriteLine(" Name:" + cacheInfo.Name)
Console.WriteLine(" IsLoaded:" + cacheInfo.IsLoaded.ToString())
Debug.Assert(cacheInfo.DocumentId = documentId)
Debug.Assert(cacheInfo.Name = "Leadtools.pdf")
Debug.Assert(Not cacheInfo.IsLoaded)
' Next load this document
Dim LoadDocumentOptions As New LoadDocumentOptions()
LoadDocumentOptions.Cache = Cache
Using document As LEADDocument = DocumentFactory.LoadFromUri(uploadUri, LoadDocumentOptions)
' Save it to the cache
document.AutoSaveToCache = False
document.AutoDeleteFromCache = False
document.SaveToCache()
End Using
' 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.ToString())
Debug.Assert(cacheInfo.DocumentId = documentId)
Debug.Assert(cacheInfo.Name = "Leadtools.pdf")
Debug.Assert(cacheInfo.IsLoaded)
End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document