diff options
Diffstat (limited to 'stage1/ClassLoaderCache.scala')
-rw-r--r-- | stage1/ClassLoaderCache.scala | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/stage1/ClassLoaderCache.scala b/stage1/ClassLoaderCache.scala new file mode 100644 index 0000000..18a0d0e --- /dev/null +++ b/stage1/ClassLoaderCache.scala @@ -0,0 +1,25 @@ +package cbt + +import java.net._ + +private[cbt] object ClassLoaderCache{ + private val cache = NailgunLauncher.classLoaderCache + def get( classpath: ClassPath )(implicit logger: Logger): ClassLoader + = cache.synchronized{ + val lib = new Stage1Lib(logger) + val key = classpath.strings.sorted.mkString(":") + if( cache.containsKey(key) ){ + logger.resolver("CACHE HIT: "++key) + cache.get(key) + } else { + logger.resolver("CACHE MISS: "++key) + val cl = new cbt.URLClassLoader( classpath, ClassLoader.getSystemClassLoader ) + cache.put( key, cl ) + cl + } + } + def remove( classpath: ClassPath ) = { + val key = classpath.strings.sorted.mkString(":") + cache.remove( key ) + } +} |