CachingDirectives

Use these directives to “wrap” expensive operations with a caching layer that runs the wrapped operation only once and returns the the cached value for all future accesses for the same key (as long as the respective entry has not expired). See caching for an introduction to how the caching support works.

Dependency

To use Akka HTTP Caching, add the module to your project:

sbt
val AkkaHttpVersion = "10.5.3"
libraryDependencies += "com.typesafe.akka" %% "akka-http-caching" % AkkaHttpVersion
Gradle
def versions = [
  ScalaBinary: "2.13"
]
dependencies {
  implementation platform("com.typesafe.akka:akka-http-bom_${versions.ScalaBinary}:10.5.3")

  implementation "com.typesafe.akka:akka-http-caching_${versions.ScalaBinary}"
}
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.typesafe.akka</groupId>
      <artifactId>akka-http-bom_${scala.binary.version}</artifactId>
      <version>10.5.3</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>com.typesafe.akka</groupId>
    <artifactId>akka-http-caching_${scala.binary.version}</artifactId>
  </dependency>
</dependencies>

Imports

Directives are available by importing:

Scala
sourceimport akka.http.scaladsl.server.directives.CachingDirectives._
Java
sourceimport static akka.http.javadsl.server.directives.CachingDirectives.*;
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.