Created
July 30, 2014 14:01
-
-
Save maiostri/90ed595b368a46ce3ff8 to your computer and use it in GitHub Desktop.
Disable browser cache in play framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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