使用 Scala 和 Play 2.5.10,我实现了以下可重用的组合操作,目的是通过更改响应标头来禁用浏览器中的缓存:
import play.api.http.HeaderNames
import play.api.mvc._
import scala.concurrent.Future
import scala.util.{Failure, Success}
import scala.concurrent.ExecutionContext.Implicits.global
case class NoCache[A](action: Action[A]) extends Action[A] with HeaderNames {
def apply(request: Request[A]): Future[Result] = {
action(request).andThen {
case Success(result) => result.withHeaders(
(CACHE_CONTROL -> "no-cache, no-store, must-revalidate"),
(PRAGMA -> "no-cache"),
(EXPIRES -> "0")
)
case Failure(result) => result
}
}
lazy val parser = action.parser
}
然后我在我的控制器操作实现中重用它,如下所示:
def link = NoCache {
deadbolt.SubjectPresent()() { implicit request =>
Future {
Ok(views.html.account.link(userService, auth))
}
}
}
我在实现中设置断点NoCache
并正确执行,但是,使用Web Developer Firefox 插件来监控网络流量我看到响应标头不包含“无缓存”修改......我做错了什么?