Helper method to quickly determine if a document exists in the cache.
public static bool IsDocumentInCache(
ObjectCache cache,
string documentId
)
public:
static bool IsDocumentInCache(
ObjectCache^ cache,
String^ documentId
)
def IsDocumentInCache(self,cache,documentId):
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://).
true if the document exists in the cache; otherwise, false.
This method uses the information described in Document Toolkit and Caching to quickly determine if the document exists in the cache.
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 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:\LEADTOOLS22\Resources\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()));
}
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