This example demonstrates the basic usage of httpcache with in-memory caching.
- Creating an HTTP client with in-memory cache
- Making cacheable requests
- Verifying cache hits with
X-From-Cacheheader - ETag-based cache validation
From the project root directory:
go run ./examples/basic/main.goOr from the examples/basic directory:
go run main.goThe first request will fetch from the server, and the second request will be served from the cache. You'll see the X-From-Cache: 1 header on cached responses.
- The in-memory cache is fast but not persistent
- Responses are cached according to HTTP caching headers
- The cache automatically handles ETag and Last-Modified validation
- No configuration needed - works out of the box