TrieMap

import scala.collection.concurrent._object o{val factorialsCache =newTrieMap[Int,Int]()def factorial(num:Int)=???// really heavy operationsdef doWorkWithFuctorial(num:Int)={val factRes = factorialsCache.getOrElseUpdate(num,{// we do not want to invoke it very often
factorial(num)// this function will be executed only if there are no records in Map for such key})// start do some work `withfactRes`
factRes
}}