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:
Create the RedisCache class which implements the ICache interface.
2, Instantiate the RedisCache class.
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.
Instantiate the Converter class with a path to the source document and the delegate from the previous step as the constructor’s parameters.
Below is the code that demonstrates how to use custom caching for GroupDocs.Conversion:
importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.ConverterSettings;importcom.groupdocs.conversion.examples.Constants;importcom.groupdocs.conversion.internal.c.a.ms.System.Diagnostics.Stopwatch;importcom.groupdocs.conversion.options.convert.PdfConvertOptions;...publicclassHowToUseCustomCacheImplementation{/**
* This example demonstrates how to implement custom cache when rendering document.
*/publicstaticvoidrun(){StringoutputDirectory=Constants.getOutputDirectoryPath(null);RedisCachecache=newRedisCache(/*"sample_"*/);ConverterSettingssettingsFactory=newConverterSettings();settingsFactory.setCache(cache);Converterconverter=newConverter(Constants.SAMPLE_DOCX,settingsFactory);PdfConvertOptionsoptions=newPdfConvertOptions();StopwatchstopWatch=Stopwatch.startNew();converter.convert("converted.pdf",options);stopWatch.stop();System.out.print(String.format("Time taken on first call to Convert method %d (ms).",stopWatch.getElapsedMilliseconds()));stopWatch.restart();converter.convert("converted-1.pdf",options);stopWatch.stop();System.out.print(String.format("Time taken on second call to Convert method %d (ms).",stopWatch.getElapsedMilliseconds()));}}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.