Skip to content

🤗 [Question]: Cache Next is not called when KeyGenerator is Defined #3034

@hcancelik

Description

@hcancelik

Question Description

Is it by design or a bug that the Next function is not called when the KeyGenerator config is defined?

Code Snippet (optional)

package main

import "github.com/gofiber/fiber/v2"
import "github.com/gofiber/fiber/v2/middleware/cache"
import "log"

func main() {
  app := fiber.New()

  app.Use(cache.New(cache.Config{
    Next: func(c *fiber.Ctx) bool {
      panic("not called")
      return c.Query("noCache") == "true"
    },
    KeyGenerator: func(c *fiber.Ctx) string {
      return fmt.Sprintf("report-%s", c.Query("startDate"))
    },
    Expiration: 30 * time.Minute,
    CacheControl: false,
  }))

  log.Fatal(app.Listen(":3000"))
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions