Skip to content

Instantly share code, notes, and snippets.

@dt
Created July 4, 2012 22:49
Show Gist options
  • Save dt/3049932 to your computer and use it in GitHub Desktop.
Save dt/3049932 to your computer and use it in GitHub Desktop.
Caching Webservice call wrapper
object CachedWS {
def apply[T](key: String)(f: => Promise[Option[T]])(implicit m: scala.reflect.ClassManifest[T]): Promise[Option[T]] =
Cache.getAs[T](key).map(t => Promise.pure(Some(t))).getOrElse{f.map(_.map{ t => Cache.set(key, t); t})}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment