vojtechrichter / http-cache-header-builder
Package info
github.com/vojtechrichter/http-cache-header-builder
pkg:composer/vojtechrichter/http-cache-header-builder
v0.0.1
2026-02-20 20:44 UTC
Requires
- php: >=8.5
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
This package is auto-updated.
Last update: 2026-05-02 20:21:28 UTC
README
Builder for HTTP cache headers like: Cache-Control, Surrogate-Control, Vary, ETag
Value combinations are being validated so you avoid meaningless cache directives.
PSR-15 example usage:
$middleware = new CacheHeaderMiddleware([ '/assets/**' => new CacheProfile( cacheControl: CacheControlHeader::immutableAsset(), vary: VaryBuilder::create()->acceptEncoding()->build(), ), '/api/**' => new CacheProfile( cacheControl: CacheControlBuilder::create() ->public() ->maxAge(60) ->sMaxAge(300) ->mustRevalidate() ->build(), vary: VaryBuilder::create()->acceptEncoding()->accept()->authorization()->build(), surrogate: SurrogateControl::maxAge(300)->withStaleWhileRevalidate(60), ), '/**' => new CacheProfile( cacheControl: CacheControlHeader::revalidate(), ), ]);