Cache.set("item.key", connectedUser)或稍後取回數據:
val maybeUser: Option[User] = Cache.getAs[User]("item.key")有一個助手方法能夠幫你取出或設置值,若是該值不存在的話:
val user: User = Cache.getOrElseAs[User]("item.key") { User.findById(connectedUser) }
def index = Cached("homePage") { Action { Ok("Hello world") } }
def userProfile = Authenticated { user => Cached(req => "profile." + user) { Action { Ok(views.html.profile(User.find(user))) } } }