com.twitter.storehaus.cache
Memoize supplies a number of functions for generating memoized versions of Scala's functions using a MutableCache instance.
For example,
import com.twitter.storehaus.cache._ scala> val sleepyToString = Memoize(MapCache.empty[Int, String].toMutable()) { i => println("CALCULATING!"); i.toString } sleepyToString: com.twitter.storehaus.cache.Memoize22[Int,String] = <function22> scala> sleepyToString(10) CALCULATING! res21: String = 10 scala> sleepyToString(10) res22: String = 10 // Get the backing function back out with backingFn: scala> sleepyToString.backingFn(10) CALCULATING! res2: String = 10
Memoize supplies a number of functions for generating memoized versions of Scala's functions using a MutableCache instance.
For example,