diff --git a/docs/middleware/cache.md b/docs/middleware/cache.md index d627c8737b..59c3521f89 100644 --- a/docs/middleware/cache.md +++ b/docs/middleware/cache.md @@ -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") }, })) @@ -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 | @@ -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()) }, diff --git a/docs/whats_new.md b/docs/whats_new.md index 1e5080a106..32ac71b429 100644 --- a/docs/whats_new.md +++ b/docs/whats_new.md @@ -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 diff --git a/middleware/cache/cache.go b/middleware/cache/cache.go index f6d9fd5532..c107b212ed 100644 --- a/middleware/cache/cache.go +++ b/middleware/cache/cache.go @@ -118,7 +118,7 @@ func New(config ...Config) fiber.Handler { ts := atomic.LoadUint64(×tamp) // 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 } diff --git a/middleware/cache/cache_test.go b/middleware/cache/cache_test.go index 0b54b07155..d529ccd9f5 100644 --- a/middleware/cache/cache_test.go +++ b/middleware/cache/cache_test.go @@ -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") }, })) diff --git a/middleware/cache/config.go b/middleware/cache/config.go index 72a7eae559..b32e9e8ce0 100644 --- a/middleware/cache/config.go +++ b/middleware/cache/config.go @@ -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 // @@ -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()) },