Search code examples
javaeclipse-rcpe4

Clear the cache during runtime - Eclipse e4


I would like to clear the Eclipse e4 cache (The .metadata directory) during runtime.

There are lots of posts for clearing the cache by setting the checkbox in the run configurations but I can't find anything on clearing the cache in the code.

I'd prefer to use a method that has already been written (if there is one) in comparison to writing my own.

If I was to do this myself then I'll do it during @PostContextCreate in the life cycle manager.

Is there a method that will do this for me or should I just delete the cache directory?

Update Here is the issue I'm trying to work around.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=430090#add_comment


Solution

  • To clear the cache at runtime I've overridden the ResourceHandler and added this to loadMostRecentModel.

    final Method m = getClass().getSuperclass().getDeclaredMethod("getWorkbenchSaveLocation", new Class<?>[] {});
    m.setAccessible(true);
    final File workbenchSaveLocation = (File) m.invoke(this, (Object[]) null);
    workbenchSaveLocation.delete();  
    

    I use reflection as the parent method is private. It would be better to do this instead of writing code to get the file myself as it ensures I always get the correct location.