Skip to content

Commit

Permalink
Rename the option to make it clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
hcancelik committed Jun 15, 2024
1 parent d8f0d5c commit b26eb02
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions docs/middleware/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ app.Get("/", func(c fiber.Ctx) error {
})
```

You can also invalidate the cache by using the `CacheInvalidation` function as shown below:
You can also invalidate the cache by using the `CacheInvalidator` function as shown below:

```go
app.Use(cache.New(cache.Config{
CacheInvalidation: func(c fiber.Ctx) bool {
CacheInvalidator: func(c fiber.Ctx) bool {
return fiber.Query[bool](c, "invalidateCache")
},
}))
Expand All @@ -80,7 +80,7 @@ app.Use(cache.New(cache.Config{
| Expiration | `time.Duration` | Expiration is the time that a cached response will live. | `1 * time.Minute` |
| 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` |
| CacheControl | `bool` | CacheControl enables client-side caching if set to true. | `false` |
| CacheInvalidation | `func(fiber.Ctx) bool` | CacheInvalidation 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` |
| 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` |
| KeyGenerator | `func(fiber.Ctx) string` | Key allows you to generate custom keys. | `func(c fiber.Ctx) string { return utils.CopyString(c.Path()) }` |
| ExpirationGenerator | `func(fiber.Ctx, *cache.Config) time.Duration` | ExpirationGenerator allows you to generate custom expiration keys based on the request. | `nil` |
| Storage | `fiber.Storage` | Store is used to store the state of the middleware. | In-memory store |
Expand All @@ -98,7 +98,7 @@ var ConfigDefault = Config{
Expiration: 1 * time.Minute,
CacheHeader: "X-Cache",
CacheControl: false,
CacheInvalidation: nil,
CacheInvalidator: nil,
KeyGenerator: func(c fiber.Ctx) string {
return utils.CopyString(c.Path())
},
Expand Down
2 changes: 1 addition & 1 deletion docs/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ DRAFT section

### Cache

We are excited to introduce a new option in our caching middleware: Cache Invalidation. This feature provides greater control over cache management, allowing you to define a custom conditions for invalidating cache entries.
We are excited to introduce a new option in our caching middleware: Cache Invalidator. This feature provides greater control over cache management, allowing you to define a custom conditions for invalidating cache entries.

### CORS

Expand Down
2 changes: 1 addition & 1 deletion middleware/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func New(config ...Config) fiber.Handler {
ts := atomic.LoadUint64(&timestamp)

// Invalidate cache if requested
if cfg.CacheInvalidation != nil && cfg.CacheInvalidation(c) && e != nil {
if cfg.CacheInvalidator != nil && cfg.CacheInvalidator(c) && e != nil {
e.exp = ts - 1
}

Expand Down
2 changes: 1 addition & 1 deletion middleware/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func Test_CacheInvalidation(t *testing.T) {
app := fiber.New()
app.Use(New(Config{
CacheControl: true,
CacheInvalidation: func(c fiber.Ctx) bool {
CacheInvalidator: func(c fiber.Ctx) bool {
return fiber.Query[bool](c, "invalidate")
},
}))
Expand Down
14 changes: 7 additions & 7 deletions middleware/cache/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ type Config struct {
// Optional. Default: false
CacheControl bool

// CacheInvalidation defines a function to invalidate the cache when returned true
// CacheInvalidator defines a function to invalidate the cache when returned true
//
// Optional. Default: nil
CacheInvalidation func(fiber.Ctx) bool
CacheInvalidator func(fiber.Ctx) bool

// Key allows you to generate custom keys, by default c.Path() is used
//
Expand Down Expand Up @@ -74,11 +74,11 @@ type Config struct {

// ConfigDefault is the default config
var ConfigDefault = Config{
Next: nil,
Expiration: 1 * time.Minute,
CacheHeader: "X-Cache",
CacheControl: false,
CacheInvalidation: nil,
Next: nil,
Expiration: 1 * time.Minute,
CacheHeader: "X-Cache",
CacheControl: false,
CacheInvalidator: nil,
KeyGenerator: func(c fiber.Ctx) string {
return utils.CopyString(c.Path())
},
Expand Down

0 comments on commit b26eb02

Please sign in to comment.