@@ -112,10 +112,11 @@ public static function getExtensionResource($extension): DispatchResource
112112 /**
113113 * @param DispatchResource $resource
114114 *
115+ * @param bool $cache
116+ *
115117 * @return Response
116- * @throws \Exception
117118 */
118- public static function create (DispatchResource $ resource )
119+ public static function create (DispatchResource $ resource, $ cache = true )
119120 {
120121 $ response = new Response ();
121122
@@ -127,20 +128,25 @@ public static function create(DispatchResource $resource)
127128 //Domain specific content will vary on the uri itself
128129 $ response ->headers ->set ("Vary " , "Accept-Encoding " );
129130
130- //Set the etag to the hash of the request uri, as it is in itself a hash
131- $ response ->setEtag ($ resource ->getHash ());
132- $ response ->setPublic ();
131+ if ($ cache )
132+ {
133+ //Set the etag to the hash of the request uri, as it is in itself a hash
134+ $ response ->setEtag ($ resource ->getHash ());
135+ $ response ->setPublic ();
133136
134- //This resource should last for 1 year in cache
135- $ response ->setMaxAge (31536000 );
136- $ response ->setSharedMaxAge (31536000 );
137- $ response ->setExpires ((new \DateTime ())->add (new \DateInterval ('P365D ' )));
137+ //This resource should last for 1 year in cache
138+ $ response ->setMaxAge (31536000 );
139+ $ response ->setSharedMaxAge (31536000 );
140+ $ response ->setExpires ((new \DateTime ())->add (new \DateInterval ('P365D ' )));
141+
142+ //Set the last modified date to now
143+ $ date = new \DateTime ();
144+ $ date ->setTimezone (new \DateTimeZone ('UTC ' ));
145+ $ response ->headers ->set ('Last-Modified ' , $ date ->format ('D, d M Y H:i:s ' ) . ' GMT ' );
146+ }
138147
139- //Set the last modified date to now
140- $ date = new \DateTime ();
141- $ date ->setTimezone (new \DateTimeZone ('UTC ' ));
142- $ response ->headers ->set ('Last-Modified ' , $ date ->format ('D, d M Y H:i:s ' ) . ' GMT ' );
143148 $ response ->setContent ($ resource ->getContent ());
149+
144150 return $ response ;
145151 }
146152}
0 commit comments