CachingBackend

sttp.client4.caching.CachingBackend
See theCachingBackend companion object
class CachingBackend[F[_], P](delegate: GenericBackend[F, P], cache: Cache[F], config: CachingConfig) extends DelegateBackend[F, P]

A backend wrapper which implements caching of HTTP responses.

Caching happens when response-as description is "cache-friendly". This excludes non-blocking streaming responses, file-based responses and WebSockets. Additionally, caching eligibility & duration is determined by the config. See CachingConfig.Default for the default behavior.

For requests which might be cached, the response's body is read into a byte array. If the response is then determined to be cacheable, it is serialized and stored in the cache. After that, the response body is adjusted as specified by response-as and returned to the user.

For details on how the cache key is created, and the responses are serialized/deserialized, see CachingConfig.

The cache will be closed (using Cache.close) when this backend is closed.

Value parameters

cache

The cache where responses will be stored. Must use the same effect type as the backend. If the backend and cache are both synchronous, this should be sttp.shared.Identity.

config

The caching backend configuration.

Attributes

Companion
object
Graph
Supertypes
class DelegateBackend[F, P]
trait GenericBackend[F, P]
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def close(): F[Unit]

Close the backend, releasing any resources (such as thread or connection pools) that have been allocated when opening or using the backend.

Close the backend, releasing any resources (such as thread or connection pools) that have been allocated when opening or using the backend.

Attributes

Definition Classes
DelegateBackend -> GenericBackend
override def send[T](request: GenericRequest[T, P & Effect[F]]): F[Response[T]]

Send the given request. Should only be used when implementing new backends, or backend wrappers. Client code should instead use the send methods on the request type, e.g. Request.send.

Send the given request. Should only be used when implementing new backends, or backend wrappers. Client code should instead use the send methods on the request type, e.g. Request.send.

Attributes

Definition Classes
GenericBackend

Implicits

Inherited implicits

implicit override def monad: MonadError[F]

A monad instance for the F effect type. Allows writing wrapper backends, which map/`flatMap`` over the return value of send.

A monad instance for the F effect type. Allows writing wrapper backends, which map/`flatMap`` over the return value of send.

Attributes

Definition Classes
DelegateBackend -> GenericBackend
Inherited from:
DelegateBackend