@@ -52,6 +52,12 @@ class RequestCacheMiddleware implements MiddlewareInterface
5252 */
5353 protected $ ignoredCookieParams ;
5454
55+ /**
56+ * @var boolean
57+ * @Flow\InjectConfiguration(path="maxPublicCacheTime")
58+ */
59+ protected $ maxPublicCacheTime ;
60+
5561 public function process (ServerRequestInterface $ request , RequestHandlerInterface $ next ): ResponseInterface
5662 {
5763 if (!$ this ->enabled ) {
@@ -82,6 +88,23 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8288 ->withoutHeader (self ::HEADER_LIFTIME )
8389 ->withoutHeader (self ::HEADER_TAGS );
8490
91+ $ publicLifetime = 0 ;
92+ if ($ this ->maxPublicCacheTime > 0 ) {
93+ if ($ lifetime > 0 && $ lifetime < $ this ->maxPublicCacheTime ) {
94+ $ publicLifetime = $ lifetime ;
95+ } else {
96+ $ publicLifetime = $ this ->maxPublicCacheTime ;
97+ }
98+ }
99+
100+ if ($ publicLifetime > 0 ) {
101+ $ entryContentHash = md5 ($ response ->getBody ()->getContents ());
102+ $ response ->getBody ()->rewind ();
103+ $ response = $ response
104+ ->withHeader ('ETag ' , '" ' . $ entryContentHash . '" ' )
105+ ->withHeader ('Cache-Control ' , 'public, max-age= ' . $ publicLifetime );
106+ }
107+
85108 $ this ->cacheFrontend ->set ($ entryIdentifier ,[ 'timestamp ' => time (), 'response ' => str ($ response ) ], $ tags , $ lifetime );
86109 $ response ->getBody ()->rewind ();
87110 return $ response ->withHeader (self ::HEADER_INFO , 'MISS: ' . $ entryIdentifier );
0 commit comments