The Ktor client provides the HttpCache plugin that allows you to save previously fetched resources in an in-memory or persistent cache.
HttpCache only requires the ktor-client-core artifact and doesn't need any specific dependencies.
HttpCache, pass it to the
install function inside a client configuration block:
This is enough to enable the client to save previously fetched resources in an in-memory cache. For example, if you make two consequent requests to a resource with the configured
Cache-Control header, the client executes only the first request and skips the second one since data is already saved in a cache.
To create a file cache storage, pass the
File instance to the
FileStorage function. Then, pass the created storage to the
privateStorage function depending on whether this storage is used as a shared or private cache.