diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-08 00:49:25 +0000 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-08 00:12:42 -0500 |
commit | 6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7 (patch) | |
tree | 6125586f4ae9fd427de6bc0bb3a94109302196a9 /stage2/BasicBuild.scala | |
parent | 151dab0984902e5a9eb03fb1a18a0da833c2ab13 (diff) | |
download | cbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.tar.gz cbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.tar.bz2 cbt-6906ad4ad5f5b018e3493af8d3d4d9df8ac1e6e7.zip |
add context based task result cache
Diffstat (limited to 'stage2/BasicBuild.scala')
-rw-r--r-- | stage2/BasicBuild.scala | 17 |
1 files changed, 17 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 + } + } } |