* Add new CacheMiddleware cache helper + add getUri method * Example of cache http middleware added * remove getUri method from RequestWrapper + add generateEtag method to CacheMiddleware * fix etag * Standardising the http cache example * Add better exemple for http cache * Implement CacheMiddleware tests and refactoring * rename example --------- Co-authored-by: Aymane <aymane@cashflowpositifi.fr> Co-authored-by: Jamie Barton <jamie@notrab.dev>
1.4 KiB
Http Cache Example
This example demonstrates how to use the http cache middleware in Dumbo
Running the Example
-
Install dependencies:
composer install
-
Start the server:
composer start
-
To test the cached route, use the curl command to send a GET request to http://localhost:8000/cached/greet. This route has the CacheMiddleware applied to it, so it should return cache control headers. Here's the command:
curl -i http://localhost:8000/cached/greet
Look for the ETag and Cache-Control headers in the response. The ETag header is a unique identifier for the version of the resource, and the Cache-Control header indicates the caching policy
-
To test the cache functionality, you can send the same request again, but this time include the If-None-Match header with the ETag value from the previous response. If the resource hasn't changed, the server should return a 304 Not Modified status. Here's the command:
curl -i -H 'If-None-Match: $ETAG' http://localhost:8000/cached/greet # curl -i -H 'If-None-Match: W/"..."' http://localhost:8000/cached/greet
-
To test the uncached route, send a GET request to http://localhost:8000/uncached/greet. This route does not have the CacheMiddleware applied to it, so it should not return cache control headers. Here's the command:
curl -i http://localhost:8000/uncached/greet