Merge pull request #4526 from eatkins/cleanup-caffeine

Cleanup caffeine
This commit is contained in:
eugene yokota 2019-01-30 15:12:00 -05:00 committed by GitHub
commit f170d0c60c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -16,17 +16,18 @@ import sbt.Project.LoadAction
import sbt.compiler.EvalImports
import sbt.internal.Aggregation.AnyKeys
import sbt.internal.CommandStrings.BootCommand
import sbt.internal._
import sbt.internal.inc.ScalaInstance
import sbt.internal.util.Types.{ const, idFun }
import sbt.internal.util.complete.Parser
import sbt.internal.util._
import sbt.internal._
import sbt.internal.util.complete.Parser
import sbt.io.syntax._
import sbt.io.{ FileTreeDataView, IO }
import sbt.util.{ Level, Logger, Show }
import xsbti.compile.CompilerCache
import scala.annotation.tailrec
import scala.concurrent.ExecutionContext
import scala.util.control.NonFatal
/** This class is the entry point for sbt. */
@ -85,13 +86,15 @@ final class ConsoleMain extends xsbti.AppMain {
object StandardMain {
private[sbt] lazy val exchange = new CommandExchange()
import scalacache._
import scalacache.caffeine._
private[sbt] lazy val cache: Cache[Any] = CaffeineCache[Any]
private[sbt] lazy val cache: scalacache.Cache[Any] = CaffeineCache[Any]
private[sbt] val shutdownHook = new Thread(() => {
exchange.shutdown
})
private[this] val closeRunnable: Runnable = () => {
cache.close()(scalacache.modes.sync.mode)
cache.close()(scalacache.modes.scalaFuture.mode(ExecutionContext.global))
exchange.shutdown()
}
private[sbt] val shutdownHook = new Thread(closeRunnable)
def runManaged(s: State): xsbti.MainResult = {
val previous = TrapExit.installManager()
@ -106,7 +109,7 @@ object StandardMain {
try {
MainLoop.runLogged(s)
} finally {
exchange.shutdown
closeRunnable.run()
if (hooked) {
Runtime.getRuntime.removeShutdownHook(shutdownHook)
}

View File

@ -227,7 +227,7 @@ private[sbt] object Definition {
val cacheFile = compileIncSetup.value.cacheFile.getAbsolutePath
val useBinary = enableBinaryCompileAnalysis.value
val s = state.value
s.log.debug(s"analysis location ${(cacheFile -> useBinary)}")
s.log.debug(s"analysis location ${cacheFile -> useBinary}")
import scalacache.modes.sync._
updateCache(StandardMain.cache)(cacheFile, useBinary)
}