@@ -21,14 +21,15 @@ public function register(Container $container)
2121 /**
2222 * Enable client-side HTTP caching
2323 *
24- * @param ResponseInterface $response PSR7 response object
25- * @param string $type Cache-Control type: "private" or "public"
26- * @param null|int|string $maxAge Maximum cache age (integer timestamp or datetime string)
24+ * @param ResponseInterface $response PSR7 response object
25+ * @param string $type Cache-Control type: "private" or "public"
26+ * @param null|int|string $maxAge Maximum cache age (integer timestamp or datetime string)
27+ * @param bool $mustRevalidate add option "must-revalidate" to Cache-Control
2728 *
2829 * @return ResponseInterface A new PSR7 response object with `Cache-Control` header
2930 * @throws InvalidArgumentException if the cache-control type is invalid
3031 */
31- public function allowCache (ResponseInterface $ response , $ type = 'private ' , $ maxAge = null )
32+ public function allowCache (ResponseInterface $ response , $ type = 'private ' , $ maxAge = null , $ mustRevalidate = false )
3233 {
3334 if (!in_array ($ type , ['private ' , 'public ' ])) {
3435 throw new InvalidArgumentException ('Invalid Cache-Control type. Must be "public" or "private". ' );
@@ -41,6 +42,10 @@ public function allowCache(ResponseInterface $response, $type = 'private', $maxA
4142 $ headerValue = $ headerValue . ', max-age= ' . $ maxAge ;
4243 }
4344
45+ if ($ mustRevalidate ) {
46+ $ headerValue = $ headerValue . ", must-revalidate " ;
47+ }
48+
4449 return $ response ->withHeader ('Cache-Control ' , $ headerValue );
4550 }
4651
0 commit comments