Created
September 4, 2017 14:11
-
-
Save qingwei91/e30d3eb49ed54430626341923aff5c0d to your computer and use it in GitHub Desktop.
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
| // 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