How to use custom cache implementation

GroupDocs.Conversion implements caching to local drive out of the box. For flexibility GroupDocs.Conversion provides and extension point which allows you to cache conversion result in your own way. You can do this by using ICache interface implementation.
Let’s see how to implement some custom cache implementation using this extension point.

Using Redis cache

The following steps should be followed.

  • Create RedisCache class which implements ICache interface.
  • Instantiate the RedisCache class.
  • Declare a delegate which will be used from Converter class as factory of ConverterSettings. In the body of this delegate, instantiate ConverterSettings class and set property setCache with the RedisCache class instance from previous step.
  • Instantiate Converter class with path to source document and the delegate from the previous step as constructor’s parameters.
  • Create instance of PdfConvertOptions class.
  • Call Convert method of Converter instance.

Below is the code that demonstrates how to use custom caching for GroupDocs.Conversion:

package com.groupdocs.conversion.examples.advanced_usage.caching;

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.ConverterSettings;
import com.groupdocs.conversion.examples.Constants;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;

public class HowToUseCustomCacheImplementation {
    * This example demonstrates how to implement custom cache when rendering document.
    public static void run()
        String outputDirectory = Constants.getOutputDirectoryPath(null);

        RedisCache cache = new RedisCache(/*"sample_"*/);
        ConverterSettings settingsFactory = new ConverterSettings();

        Converter converter = new Converter(Constants.SAMPLE_DOCX, settingsFactory);
        PdfConvertOptions options = new PdfConvertOptions();

        Stopwatch stopWatch = Stopwatch.startNew();
        converter.convert("converted.pdf", options);

        System.out.print(String.format("Time taken on first call to Convert method %d (ms).", stopWatch.getElapsedMilliseconds()));

        converter.convert("converted-1.pdf", options);

        System.out.print(String.format("Time taken on second call to Convert method %d (ms).", stopWatch.getElapsedMilliseconds()));

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Document Converter Apps

Along with full-featured Java library we provide free Apps and free services for document conversion. In order to see a full potential of GroupDocs.Conversion, you are welcome to convert DOC to PDF, DOC to XLSX, PDF to DOC, PDF to XLSX, PPT to DOC and more with Free Online Document Converter App or get a full advantage of Free Online Document Converter Suite with advanced conversion settings and many more enterprise built-in features. Please note that more premium features, advanced options and enhanced document management experience is available for signed-in users at for FREE.
If you don’t own an account yet, register it now for free! No credit card is required!