aboutsummaryrefslogtreecommitdiff
path: root/stage2
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-11-08 00:49:25 +0000
committerChristopher Vogt <oss.nsp@cvogt.org>2016-11-08 00:12:42 -0500
commit6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7 (patch)
tree6125586f4ae9fd427de6bc0bb3a94109302196a9 /stage2
parent151dab0984902e5a9eb03fb1a18a0da833c2ab13 (diff)
downloadcbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.tar.gz
cbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.tar.bz2
cbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.zip
add context based task result cache
Diffstat (limited to 'stage2')
-rw-r--r--stage2/BasicBuild.scala17
-rw-r--r--stage2/Stage2.scala1
2 files changed, 18 insertions, 0 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala
index 128d2f8..ef4757e 100644
--- a/stage2/BasicBuild.scala
+++ b/stage2/BasicBuild.scala
@@ -244,4 +244,21 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge
// ========== cbt internals ==========
def finalBuild: BuildInterface = this
override def show = this.getClass.getSimpleName ++ "(" ++ projectDirectory.string ++ ")"
+
+ // TODO: allow people not provide the method name, maybe via macro
+ /**
+ caches given value in context keyed with given key and projectDirectory
+ the context is fresh on every complete run of cbt
+ */
+ def cached[T <: AnyRef](name: String)(task: => T): T = {
+ val cache = context.taskCache
+ val key = (projectDirectory,name)
+ if( cache.containsKey(key) ){
+ cache.get(key).asInstanceOf[T]
+ } else{
+ val value = task
+ cache.put( key, value )
+ value
+ }
+ }
}
diff --git a/stage2/Stage2.scala b/stage2/Stage2.scala
index b1539bf..d585cd0 100644
--- a/stage2/Stage2.scala
+++ b/stage2/Stage2.scala
@@ -39,6 +39,7 @@ object Stage2 extends Stage2Base{
null,
args.permanentKeys,
args.permanentClassLoaders,
+ new java.util.concurrent.ConcurrentHashMap,
args.cache,
args.cbtHome,
args.cbtHome,