How to use custom cache implementation

GroupDocs.Conversion implements caching to local drive out of the box. For flexibility GroupDocs.Conversion provides an extension point that allows you to cache conversion results 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

To implement the Redis cache, follow these steps:

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

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

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()));