4. The Java way:
● Unavoidable repetition
● Weak against refactoring
KILLER
FEATURE! Method memoization
public int foo(int a, int b, String c) {
String key = toKey(“foo”, a, b, c);
return withCache(key, () -> {
// … do stuff …
return x;
});
}
5. The Spring way:
● AOP, Proxy objects = runtime magic
● Some restrictions, e.g. cannot call method
from the same class
KILLER
FEATURE! Method memoization
@Cacheable(“cacheName”)
public int foo(int a, int b, String c) {
// … do stuff ...
return x;
}
6. The ScalaCache way:
● Macros = compile-time magic!
● Auto-generates cache key, e.g. “com.
bar.Baz.foo(123, 456, xyz)”
KILLER
FEATURE! Method memoization
def foo(a: Int, b: Int, c: String): Int = memoize {
// … do stuff …
x
}
8. Roadmap
Investigating new features for ScalaCache
● Async support
● Versioning, a.k.a. key-based expiration
● Customizable serialization
● API improvements
● Integration with browser caching à la Play
Cache
9. Try it!
scalaVersion := 2.11.0
resolvers += “Sonatype snapshots” at
“https://oss.sonatype.org/content/repositories/snapshots/”
libraryDependencies +=
“com.github.cb372” %% “scalacache” % “0.3.0-SNAPSHOT”
More info at https://github.com/cb372/scalacache