This PR contains the work done to add cache-control headers to static file responses by configuring the `FileMiddleware` middleware to tag served static files with *Cache-Control* directives, tuned per media type. To provide further details about the work done: * Added a cache control that sets per-type policies: text assets (CSS/JS) get public, max-age, must-revalidate; images get public, max-age; everything else gets a default public, max-age. * Files stay validated via `ETag/Last-Modified` header. * Made the max-age values configurable, with defaults, via new cache constants. Reviewed-on: rock-n-code/loud-amsterdam#6 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
12 lines
519 B
Swift
12 lines
519 B
Swift
extension Int {
|
|
/// A namespace for the cache's default configuration values.
|
|
public enum Cache {
|
|
/// The default max-age, in seconds, applied to text-based static files (1 hour).
|
|
public static let maxAgeText = 3_600
|
|
/// The default max-age, in seconds, applied to image static files (1 week).
|
|
public static let maxAgeImage = 604_800
|
|
/// The default max-age, in seconds, applied to all other static files (1 day).
|
|
public static let maxAgeDefault = 86_400
|
|
}
|
|
}
|