Skip to content

Instantly share code, notes, and snippets.

@qingwei91
Created September 4, 2017 14:11
Show Gist options
  • Select an option

  • Save qingwei91/e30d3eb49ed54430626341923aff5c0d to your computer and use it in GitHub Desktop.

Select an option

Save qingwei91/e30d3eb49ed54430626341923aff5c0d to your computer and use it in GitHub Desktop.
// the signature is slightly different, as our macro need to access `get` and `put` method, but not `getOrElse`
// you can implement both signature though
trait SyncCache[K, V] {
def get(k: K): Option[V]
def put(k: K, v: V): Unit
}
val cacheBackend = new SyncCache[Int, Int]
@cache(cacheBackend)
def fib(i: Int): Int = i match {
case 0 => 0
case 1 => 1
case n => fib(n - 2) + fib(n - 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment