Skip to content

Instantly share code, notes, and snippets.

@maiostri
Created July 30, 2014 14:01
Show Gist options
  • Save maiostri/90ed595b368a46ce3ff8 to your computer and use it in GitHub Desktop.
Save maiostri/90ed595b368a46ce3ff8 to your computer and use it in GitHub Desktop.
Disable browser cache in play framework
package global
import play.api._
import play.api.mvc._
import play.api.Play.current
import play.api.http.HeaderNames._
import play.api.mvc.Results._
import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext
object Global extends GlobalSettings {
def NoCache(action: EssentialAction): EssentialAction = EssentialAction { request =>
action(request).map(_.withHeaders(PRAGMA -> "no-cache"))
}
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
if (Play.isDev) {
super.onRouteRequest(request).map { handler =>
handler match {
case a: EssentialAction => NoCache(a)
case other => other
}
}
} else {
super.onRouteRequest(request)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment