diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-02-06 13:03:36 -0500 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-04 15:06:30 -0500 |
commit | 974942db43ff2d1fa7ba71ad60f9bb9eae2d8631 (patch) | |
tree | d7235df9d4d6a67753dc2a20ab6bfcb7a24dc74c /stage1/Cache.scala | |
download | cbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.tar.gz cbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.tar.bz2 cbt-974942db43ff2d1fa7ba71ad60f9bb9eae2d8631.zip |
CBT Version 1.0-BETA
Diffstat (limited to 'stage1/Cache.scala')
-rw-r--r-- | stage1/Cache.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/stage1/Cache.scala b/stage1/Cache.scala new file mode 100644 index 0000000..6e6b9eb --- /dev/null +++ b/stage1/Cache.scala @@ -0,0 +1,14 @@ +package cbt +/** +Caches exactly one value +Is there a less boiler-platy way to achieve this, that doesn't +require creating an instance for each thing you want to cache? +*/ +class Cache[T]{ + private var value: Option[T] = None + def apply(value: => T) = this.synchronized{ + if(!this.value.isDefined) + this.value = Some(value) + this.value.get + } +} |