Created
August 8, 2017 11:58
-
-
Save rahilb/01fea2e9d0faed915366e6b47a2d2907 to your computer and use it in GitHub Desktop.
guava scalaz memo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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