1 Reply Latest reply: Jun 22, 2010 3:00 AM by David Bosschaert RSS

Removing cached entry in VFSCLPolicy on load

Ales Justin Master

Does something like this make sense to add directly, or should it be optional?

 

   public VFSClassLoaderPolicy(String name, VirtualFile[] roots, VirtualFile[] excludedRoots)
   {
        ...

        this.excludedRoots = excludedRoots;
+      addClassFoundHandler(new VFSCacheRemove());
    }
 
+
+   private class VFSCacheRemove implements ClassFoundHandler
+   {
+      public void classFound(ClassFoundEvent event)
+      {
+         String className = event.getClassName();
+         String path = ClassLoaderUtils.classNameToPath(className);
+         vfsCache.remove(path); // remove the entry once we loaded the class
+      }
+   }
 }

 

This would definitely decrease the memory, since every already loaded class's lookup cache would be released.

And with CL cache fixed, we access the class on next invocaton directly form CL cache, hence no need to path cache.