Skip to content

Commit 8d22f6e

Browse files
Add docs from gofiber/fiber@aedffa1
1 parent 6bf1020 commit 8d22f6e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

docs/core/middleware/cache.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ id: cache
66

77
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.
88

9+
By default, cached responses expire after five minutes and the middleware stores up to 1 MB of response bodies.
10+
911
Request directives
1012

1113
- `Cache-Control: no-cache` returns the latest response while still caching it, so the status is always `miss`.
@@ -67,7 +69,7 @@ app.Use(cache.New(cache.Config{
6769
return fiber.Query[bool](c, "noCache")
6870
},
6971
Expiration: 30 * time.Minute,
70-
CacheControl: true,
72+
DisableCacheControl: true,
7173
}))
7274
```
7375

@@ -107,33 +109,33 @@ app.Use(cache.New(cache.Config{
107109
| Property | Type | Description | Default |
108110
| :------------------- | :--------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------- |
109111
| 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` |
111113
| 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()) }` |
115117
| ExpirationGenerator | `func(fiber.Ctx, *cache.Config) time.Duration` | ExpirationGenerator allows you to generate custom expiration keys based on the request. | `nil` |
116118
| Storage | `fiber.Storage` | Storage is used to store the state of the middleware. | In-memory store |
117119
| 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) |
119121
| Methods | `[]string` | Methods specifies the HTTP methods to cache. | `[]string{fiber.MethodGet, fiber.MethodHead}` |
120122

121123
## Default Config
122124

123125
```go
124126
var ConfigDefault = Config{
125127
Next: nil,
126-
Expiration: 1 * time.Minute,
128+
Expiration: 5 * time.Minute,
127129
CacheHeader: "X-Cache",
128-
CacheControl: false,
130+
DisableCacheControl: false,
129131
CacheInvalidator: nil,
130132
KeyGenerator: func(c fiber.Ctx) string {
131133
return utils.CopyString(c.Path())
132134
},
133135
ExpirationGenerator: nil,
134136
StoreResponseHeaders: false,
135137
Storage: nil,
136-
MaxBytes: 0,
138+
MaxBytes: 1 * 1024 * 1024,
137139
Methods: []string{fiber.MethodGet, fiber.MethodHead},
138140
}
139141
```

0 commit comments

Comments
 (0)