You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/middleware/cache.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ id: cache
6
6
7
7
Cache middleware for [Fiber](https://github.com/gofiber/fiber) that intercepts responses and stores the body, `Content-Type`, and status code under a key derived from the request path and method. Special thanks to [@codemicro](https://github.com/codemicro/fiber-cache) for contributing this middleware to Fiber core.
8
8
9
+
By default, cached responses expire after five minutes and the middleware stores up to 1 MB of response bodies.
10
+
9
11
Request directives
10
12
11
13
-`Cache-Control: no-cache` returns the latest response while still caching it, so the status is always `miss`.
| Next |`func(fiber.Ctx) bool`| Next defines a function that is executed before creating the cache entry and can be used to execute the request without cache creation. If an entry already exists, it will be used. If you want to completely bypass the cache functionality in certain cases, you should use the [skip middleware](skip.md). |`nil`|
110
-
| Expiration |`time.Duration`| Expiration is the time that a cached response will live. |`1 * time.Minute`|
112
+
| Expiration |`time.Duration`| Expiration is the time that a cached response will live. |`5 * time.Minute`|
111
113
| CacheHeader |`string`| CacheHeader is the header on the response header that indicates the cache status, with the possible return values "hit," "miss," or "unreachable." |`X-Cache`|
112
-
|CacheControl |`bool`| CacheControl enables client-side caching if set to true. |`false`|
113
-
| CacheInvalidator |`func(fiber.Ctx) bool`| CacheInvalidator defines a function that is executed before checking the cache entry. It can be used to invalidate the existing cache manually by returning true. |`nil`|
114
-
| KeyGenerator |`func(fiber.Ctx) string`|Key allows you to generate custom keys. The HTTP method is appended automatically.|`func(c fiber.Ctx) string { return utils.CopyString(c.Path()) }`|
114
+
|DisableCacheControl |`bool`| DisableCacheControl omits the `Cache-Control` header when set to `true`. |`false`|
115
+
| CacheInvalidator |`func(fiber.Ctx) bool`| CacheInvalidator defines a function that is executed before checking the cache entry. It can be used to invalidate the existing cache manually by returning true. |`nil`|
116
+
| KeyGenerator |`func(fiber.Ctx) string`|KeyGenerator allows you to generate custom keys. The HTTP method is appended automatically. |`func(c fiber.Ctx) string { return utils.CopyString(c.Path()) }`|
115
117
| ExpirationGenerator |`func(fiber.Ctx, *cache.Config) time.Duration`| ExpirationGenerator allows you to generate custom expiration keys based on the request. |`nil`|
116
118
| Storage |`fiber.Storage`| Storage is used to store the state of the middleware. | In-memory store |
117
119
| StoreResponseHeaders |`bool`| StoreResponseHeaders allows you to store additional headers generated by next middlewares & handler. |`false`|
118
-
| MaxBytes |`uint`| MaxBytes is the maximum number of bytes of response bodies simultaneously stored in cache. |`0` (No limit) |
120
+
| MaxBytes |`uint`| MaxBytes is the maximum number of bytes of response bodies simultaneously stored in cache. |`1 * 1024 * 1024` (~1 MB)|
119
121
| Methods |`[]string`| Methods specifies the HTTP methods to cache. |`[]string{fiber.MethodGet, fiber.MethodHead}`|
0 commit comments