Scala Play 2.5 动作组合与 Deadbolt-2 动作

Scala Play 2.5 Action composition with Deadbolt-2 actions

我正在开发 Scala Play 应用程序,需要通过在响应的 HTTP headers 中设置参数来禁用浏览器缓存的许多控制器操作。我决定创建一个 NoCache 复合动作,因为我也在使用 Deadbolt-2(并且需要 Deadbolt-2 的 AuthenticatedRequest[_]),它看起来像这样:

package action

import be.objectify.deadbolt.scala.AuthenticatedRequest
import play.api.http.HeaderNames
import play.api.mvc._

import scala.concurrent.Future
import scala.util.Success

case class NoCache[A](action: Action[A]) extends Action[A] with HeaderNames {
  def apply(request: AuthenticatedRequest[A]): Future[Result] = {
    action(request).andThen {
      case Success(result) => result.withHeaders(
        (CACHE_CONTROL -> "no-cache, no-store, must-revalidate"),
        (PRAGMA -> "no-cache"),
        (EXPIRES -> "0")
      )
    }
  }

  lazy val parser = action.parser
}

但是它不会编译尝试将此操作混合到我的控制器操作实现中,例如

def link = deadbolt.SubjectPresent()() andThen NoCache() { implicit request =>

def link = NoCache(deadbolt.SubjectPresent()()) { implicit request =>

但看不到如何组合它们...

我找到了如何完成单个操作:

def index = NoCache {
  deadbolt.WithAuthRequest()() { implicit request =>
    Future {
      Ok(views.html.index(userService))
    }
  }
} 

但是,我仍然没有找到如何将NoCache应用到整个控制器class。