Implement your Document Cache in the Cloud

Posted on 2023-10-12 Halah Villalobos

cloud

With the LEADTOOLS Document Service, you can choose how you want to manage and store cached documents. We have new samples for implementing cloud solutions for your Document Service’s caching capabilities, allowing you to utilize Azure or AWS for your cache.

Caching documents is crucial for enhancing performance and user experience, especially in data-intensive applications where quick retrieval of documents is a priority. By storing frequently accessed documents in a cache, you significantly reduce the time it takes to fetch them, as they can be retrieved from a faster, closer storage medium rather than the original data source. This is particularly beneficial for many companies across multiple technologies such as fintech, where financial documents are often reviewed multiple times.

To understand more of the basics, be sure to check out this documentation page on LEAD's Document Toolkit and Caching. The rest of this blog will briefly describe three tutorials on how to implement Azure Redis Cache and AWS S3 Bucket Cache with the LEADTOOLS Document Service.

Code Snippets

All three tutorials include code on how to create and set the Cache Manager and run each projects. The code begins and ends the same when setting the cache in the document service for each of these as well. Depending on the solution you have chosen to manage and store cache documents, you would then set that option like so:


public static void CreateCache()
        {
            //Called by InitializeService the first time the service is run 
            //Initialize the global ICacheManager object
            //ICacheManager cacheManager = null;  

//Set one of the sample codes below here if (cacheManager == null) throw new InvalidOperationException("Could not find a valid LEADTOOLS cache system configuration."); cacheManager.Initialize(); _cacheManager = cacheManager; }

Azure

Microsoft Azure Azure is Microsoft’s answer to cloud solutions. Our caching examples take advantage of its popular Redis Cache and Storage Blob functionality.

Redis Cache

We offer a sample for implementing an Azure Redis Cache. Please note that this implementation requires you to save large binary data directly to the cache and may not be suitable for documents that are accessible from multiple servers.

Sample Code

Add the following code snipping to where you set your cache manager in the Document Service:


            RedisCacheManager cacheManager = new RedisCacheManager(WebRootPath, null); 

To effectively use a Redis Cache with multiple servers, it is recommended that you store the document’s data in a Storage Blob instead of directly into the Redis Cache. You can find more information about this implementation below.

Redis Cache with Storage Blobs

If you wanted to use the Azure Cloud to maintain a cache that can be effectively used by multiple servers, we recommend also using Redis Cache with Storage Blobs.

In this example, the association of the document ID and the document’s Blob location is stored in the Redis Cache, while the document’s binary data is stored in a Storage Blob. This will help minimize the load on the Redis Cache instance and help organize the document data in a traversable directory.

This approach stores binary data to an Azure Storage Blob to keep multiple servers synchronized.

Sample Code

Add the following code snipping to where you set your cache manager in the Document Service:


            cacheManager = new RedisWithBlobsCacheManager(WebRootPath, null);

AWS

Amazon AWS

AWS is Amazon’s answer to cloud solutions. Our caching example takes advantage of its popular S3 Bucket functionality.

S3 Bucket Cache

To use AWS to maintain a document cache, you will want to store the document data in S3 Buckets. By using S3 Buckets for our cache, we can have persistent storage so we can easily retrieve documents. The document’s data will be stored in the S3 Bucket in JSON format, which is compatible between Java and .NET applications, and allows the data to be used backward compatible with legacy versions of the LEADTOOLS SDK.

Sample Code

Add the following code snipping to where you set your cache manager in the Document Service:


            S3BucketCacheManager cacheManager = new S3BucketCacheManager(WebRootPath, null);

Start Running your own Document Service!

Download our FREE 60-day evaluation SDK to test and walk through these tutorials and gain access to all of our other features! During this evaluation time, you can receive our fully-sourced demos and get support from our superb support staff.

Need more hands-on help? Schedule a walk-through with our support team to check out our many features that will expedite your application development!

For pricing or licensing questions, contact our sales team via email or call us at 704-332-5532. Be sure to check out our product wizard and pricing estimator as well.

LEADTOOLS Blog

LEADTOOLS Powered by Apryse,the Market Leading PDF SDK,All Rights Reserved