alwaysCache
Wraps its inner Route with caching support using the given spray.caching.Cache implementation and the in-scope keyer function.
Signature
def alwaysCache(cache: Cache[CachingDirectives.RouteResponse])
(implicit keyer: CacheKeyer, factory: ActorRefFactory): Directive0
The signature shown is simplified, the real signature uses magnets. [1]
[1] | See The Magnet Pattern for an explanation of magnet-based overloading. |
Description
Like cache but doesn’t regard a Cache-Control request header for deciding if the cache should be circumvented.
Note
Caching directives are not automatically in scope, see Usage about how to enable them.
Example
var i = 0
val route =
cache(routeCache()) {
complete {
i += 1
i.toString
}
}
Get("/") ~> route ~> check {
responseAs[String] === "1"
}
// now cached
Get("/") ~> route ~> check {
responseAs[String] === "1"
}
// caching prevented
Get("/") ~> `Cache-Control`(CacheDirectives.`no-cache`) ~> route ~> check {
responseAs[String] === "2"
}