From 135609e5b0656a05eb9e6d4f14e0ca2165edb81e Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 25 Mar 2011 21:37:17 -0400 Subject: [PATCH] temporary hack to avoid reading Analysis every compile --- main/AggressiveCompile.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main/AggressiveCompile.scala b/main/AggressiveCompile.scala index 25623e789..e7f8b2911 100644 --- a/main/AggressiveCompile.scala +++ b/main/AggressiveCompile.scala @@ -89,5 +89,19 @@ class AggressiveCompile(cacheDirectory: File) def javaOnly(f: File) = f.getName.endsWith(".java") import AnalysisFormats._ - val store = AnalysisStore.sync(AnalysisStore.cached(FileBasedStore(cacheDirectory))) + val store = AggressiveCompile.staticCache(cacheDirectory, AnalysisStore.sync(AnalysisStore.cached(FileBasedStore(cacheDirectory)))) +} +private object AggressiveCompile +{ + import collection.mutable + import java.lang.ref.{Reference,SoftReference} + private[this] val cache = new collection.mutable.HashMap[File, Reference[AnalysisStore]] + private def staticCache(file: File, backing: => AnalysisStore): AnalysisStore = + synchronized { + cache get file flatMap { ref => Option(ref.get) } getOrElse { + val b = backing + cache.put(file, new SoftReference(b)) + b + } + } } \ No newline at end of file