Cache middleware for Fiber that intercepts responses and stores the body,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/gofiber/fiber/llms.txt
Use this file to discover all available pages before exploring further.
Content-Type, and status code under a key derived from the request path and method. Special thanks to @codemicro for contributing this middleware to Fiber core.
By default, cached responses expire after five minutes and the middleware stores up to 1 MB of response bodies.
Request Directives
Cache-Control: no-cachereturns the latest response while still caching it, so the status is alwaysmissCache-Control: no-storeskips caching and always forwards a fresh response
Cache-Control: max-age directive, its value sets the cache entry’s expiration.
Cacheable Status Codes
The middleware caches these RFC 7231 status codes:200: OK203: Non-Authoritative Information204: No Content206: Partial Content300: Multiple Choices301: Moved Permanently404: Not Found405: Method Not Allowed410: Gone414: URI Too Long501: Not Implemented
unreachable cache status.
Signatures
Usage
Basic Example
Custom Key and Expiration
Customize the cache key and expiration; the HTTP method is appended automatically:Cache Invalidation
UseCacheInvalidator to invalidate entries programmatically:
Configuration
Executed before creating the cache entry. Can be used to execute the request without cache creation. If an entry already exists, it will be used. To completely bypass the cache functionality in certain cases, use the skip middleware.
Time that a cached response will live.
Header on the response that indicates the cache status, with possible return values “hit,” “miss,” or “unreachable.”
Omits the
Cache-Control header when set to true.Executed before checking the cache entry. Can be used to invalidate the existing cache manually by returning true.
Turns off cache key redaction in logs and error messages when set to
true.Allows you to generate custom keys. The HTTP method is appended automatically.
Allows you to generate custom expiration keys based on the request.
Used to store the state of the middleware.
Allows you to store additional headers generated by next middlewares & handler.
Maximum number of bytes of response bodies simultaneously stored in cache (~1 MB).
Specifies the HTTP methods to cache.