CachingDirectives

Use these directives to “wrap” expensive operations with a caching layer that runs the wrapped operation only once and returns 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 Apache Pekko HTTP Caching, add the module to your project:

sbt
val PekkoHttpVersion = "1.1.0"
libraryDependencies += "org.apache.pekko" %% "pekko-http-caching" % PekkoHttpVersion
Gradle
def versions = [
  ScalaBinary: "2.13"
]
dependencies {
  implementation platform("org.apache.pekko:pekko-http-bom_${versions.ScalaBinary}:1.1.0")

  implementation "org.apache.pekko:pekko-http-caching_${versions.ScalaBinary}"
}
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.pekko</groupId>
      <artifactId>pekko-http-bom_${scala.binary.version}</artifactId>
      <version>1.1.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>org.apache.pekko</groupId>
    <artifactId>pekko-http-caching_${scala.binary.version}</artifactId>
  </dependency>
</dependencies>

Imports

Directives are available by importing:

Scala
sourceimport org.apache.pekko
import pekko.http.scaladsl.server.directives.CachingDirectives._
Java
sourceimport static org.apache.pekko.http.javadsl.server.directives.CachingDirectives.*;