Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 2.52 KB

caching.md

File metadata and controls

38 lines (26 loc) · 2.52 KB

Required dependencies: io.ktor:%artifact_name%

The CachingHeaders plugin adds the capability to configure the Cache-Control and Expires headers used for HTTP caching. You can introduce different caching strategies for specific content types, such as images, CSS and JavaScript files, and so on.

Add dependencies {id="add_dependencies"}

Install CachingHeaders {id="install_plugin"}

After installing %plugin_name%, you can configure caching settings for various content types.

Configure caching {id="configure"}

To configure the %plugin_name% plugin, you need to define the options function to provide specified caching options for a given ApplicationCall and content type. The code snippet from the caching-headers example shows how to add the Cache-Control header with the max-age option for CSS and JSON:

{src="snippets/caching-headers/src/main/kotlin/com/example/Application.kt" lines="21-29"}

The CachingOptions object accepts Cache-Control and Expires header values as parameters:

  • The cacheControl parameter accepts a CacheControl value. You can use CacheControl.MaxAge to specify the max-age parameter and related settings, such as visibility, revalidation options, and so on. You can disable caching by using CacheControl.NoCache/CacheControl.NoStore.
  • The expires parameter allows you to specify the Expires header as a GMTDate or ZonedDateTime value.