Slim 3 uses the optional standalone slimphp/Slim-HttpCache PHP component
for HTTP caching. You can use this component to create and return responses that
contain Cache
, Expires
, ETag
, and Last-Modified
headers that control
when and how long application output is retained by client-side caches.
Execute this bash command from your project’s root directory:
The slimphp/Slim-HttpCache
component contains a service provider and an application
middleware. You should add both to your application like this:
Use the service provider’s withEtag()
method to create a Response object
with the desired ETag
header. This method accepts a PSR7 response object,
and it returns a cloned PSR7 response with the new HTTP header.
Use the service provider’s withExpires()
method to create a Response object
with the desired Expires
header. This method accepts a PSR7 response object,
and it returns a cloned PSR7 response with the new HTTP header.
Use the service provider’s withLastModified()
method to create a Response object
with the desired Last-Modified
header. This method accepts a PSR7 response object,
and it returns a cloned PSR7 response with the new HTTP header.