Skip to content

Instantly share code, notes, and snippets.

@rahilb
Created August 8, 2017 11:58
Show Gist options
  • Select an option

  • Save rahilb/01fea2e9d0faed915366e6b47a2d2907 to your computer and use it in GitHub Desktop.

Select an option

Save rahilb/01fea2e9d0faed915366e6b47a2d2907 to your computer and use it in GitHub Desktop.
guava scalaz memo
def guavaMemo[K, V](ttl: CacheTtl): Memo[K, V]
= Memo.memo[K, V] { method: (K => V) =>
val builder: CacheBuilder[AnyRef, AnyRef] = CacheBuilder.newBuilder()
builder.expireAfterWrite(ttl.time, ttl.unit)
val cache = builder.build().asInstanceOf[Cache[K, V]]
def ret(key: K): V = cache.get(key, new Callable[V] {
override def call(): V = {
method(key)
}
})
ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment