Free Support Forum -

What is the difference between clearing temp files and clearing cache in Java

reading the documentation, it is not clear to me the purpose and difference between methods clearTempFiles() and clearCache(), both from com.groupdocs.viewer.handler.ViewerHandler. What is the difference? when should I use each one?

Sorry if this question sounds silly.


1 Like


While rendering documents, API creates temporary files which were removed automatically after each operation. As removing temporary files is a time-consuming operation. So, we introduced clearTempFiles method. This method is thread-safe and can be called any time. It won’t affect documents rendering. GroupDocs.Viewer for Java uses a default system temporary folder to store temp files, it can be changed by setting temporary directory in process properties e.g. System.setProperty("", "c:/my_temp_files/");

Please note that API uses cache to speed-up the document processing time. For example, if you render a document, it is saved in cache for future use. Hence, if same document is being rendered again, it will be rendered quickly.
If you want to programmatically clear the cached files, you will use this method. Please see this article for further details.

Hi @atirtahir3, thank you for your reply.

I think I got it, clearCache() deletes all contents of the cache folder I define in ViewerConfig object and clearTempFiles() deletes some temporal files GroupDocs created while rendering in System.getProperty(“”) directory.

So, I assume I should call clearTempFiles() with some frequency to avoid those temporal files consume too much space, right?

1 Like


Yes, you are right.