Skip to content

Commit ab34d1d

Browse files
authored
📒docs: Fix Cache middleware docs (#3644)
1 parent c01bcca commit ab34d1d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

docs/middleware/cache.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ id: cache
44

55
# Cache
66

7-
Cache middleware for [Fiber](https://github.com/gofiber/fiber) designed to intercept responses and cache them. This middleware will cache the `Body`, `Content-Type` and `StatusCode` using the `c.Path()` as unique identifier. Special thanks to [@codemicro](https://github.com/codemicro/fiber-cache) for creating this middleware for Fiber core!
7+
Cache middleware for [Fiber](https://github.com/gofiber/fiber) designed to intercept responses and cache them. This middleware caches the `Body`, `Content-Type`, and `StatusCode` using a key built from the request path and method. Special thanks to [@codemicro](https://github.com/codemicro/fiber-cache) for creating this middleware for Fiber core!
88

99
Request Directives<br />
1010
`Cache-Control: no-cache` will return the up-to-date response but still caches it. You will always get a `miss` cache status.<br />
1111
`Cache-Control: no-store` will refrain from caching. You will always get the up-to-date response.
1212

13+
If the server response contains a `Cache-Control: max-age` directive, its value is used as the expiration time for the cache entry.
14+
1315
Cacheable Status Codes<br />
1416

1517
This middleware caches responses with the following status codes according to RFC7231:
@@ -67,7 +69,7 @@ app.Use(cache.New(cache.Config{
6769
}))
6870
```
6971

70-
Or you can custom key and expire time like this:
72+
Or you can customize the key and expiration time like this (the HTTP method is automatically appended to the key):
7173

7274
```go
7375
app.Use(cache.New(cache.Config{
@@ -107,9 +109,9 @@ The `CacheInvalidator` function allows you to define custom conditions for cache
107109
| 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` |
108110
| CacheControl | `bool` | CacheControl enables client-side caching if set to true. | `false` |
109111
| 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` |
110-
| KeyGenerator | `func(fiber.Ctx) string` | Key allows you to generate custom keys. | `func(c fiber.Ctx) string { return utils.CopyString(c.Path()) }` |
112+
| 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()) }` |
111113
| ExpirationGenerator | `func(fiber.Ctx, *cache.Config) time.Duration` | ExpirationGenerator allows you to generate custom expiration keys based on the request. | `nil` |
112-
| Storage | `fiber.Storage` | Store is used to store the state of the middleware. | In-memory store |
114+
| Storage | `fiber.Storage` | Storage is used to store the state of the middleware. | In-memory store |
113115
| StoreResponseHeaders | `bool` | StoreResponseHeaders allows you to store additional headers generated by next middlewares & handler. | `false` |
114116
| MaxBytes | `uint` | MaxBytes is the maximum number of bytes of response bodies simultaneously stored in cache. | `0` (No limit) |
115117
| Methods | `[]string` | Methods specifies the HTTP methods to cache. | `[]string{fiber.MethodGet, fiber.MethodHead}` |

middleware/cache/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
// Config defines the config for middleware.
1111
type Config struct {
12-
// Store is used to store the state of the middleware
12+
// Storage is used to store the state of the middleware
1313
//
14-
// Default: an in memory store for this process only
14+
// Default: an in-memory store for this process only
1515
Storage fiber.Storage
1616

1717
// Next defines a function to skip this middleware when returned true.
@@ -31,7 +31,8 @@ type Config struct {
3131
// }
3232
KeyGenerator func(fiber.Ctx) string
3333

34-
// allows you to generate custom Expiration Key By Key, default is Expiration (Optional)
34+
// ExpirationGenerator allows you to generate a custom expiration per request.
35+
// If nil, the Expiration value is used.
3536
//
3637
// Default: nil
3738
ExpirationGenerator func(fiber.Ctx, *Config) time.Duration
@@ -66,7 +67,8 @@ type Config struct {
6667
// Optional. Default: false
6768
CacheControl bool
6869

69-
// allows you to store additional headers generated by next middlewares & handler
70+
// StoreResponseHeaders allows you to store additional headers generated by
71+
// next middlewares and handlers.
7072
//
7173
// Default: false
7274
StoreResponseHeaders bool

0 commit comments

Comments
 (0)