aboutsummaryrefslogtreecommitdiff
path: root/stage1/Cache.scala
blob: 6e6b9eb0b5d331efa1bb6220d5043469a473f747 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
  }
}