Skip to content

Commit

Permalink
Merge branch 'feat-keyauth-fallback-keylookup' of ghgray101:dave-gray…
Browse files Browse the repository at this point in the history
…101/fiber into feat-keyauth-fallback-keylookup
  • Loading branch information
dave-gray101 committed Jun 16, 2024
2 parents 7191f65 + 8c13f25 commit 1004aa0
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions middleware/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cache

import (
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -95,22 +96,17 @@ func New(config ...Config) fiber.Handler {
return c.Next()
}

// Only cache selected methods
var isExists bool
for _, method := range cfg.Methods {
if c.Method() == method {
isExists = true
}
}
requestMethod := c.Method()

if !isExists {
// Only cache selected methods
if !slices.Contains(cfg.Methods, requestMethod) {
c.Set(cfg.CacheHeader, cacheUnreachable)
return c.Next()
}

// Get key from request
// TODO(allocation optimization): try to minimize the allocation from 2 to 1
key := cfg.KeyGenerator(c) + "_" + c.Method()
key := cfg.KeyGenerator(c) + "_" + requestMethod

// Get entry from pool
e := manager.get(key)
Expand Down

0 comments on commit 1004aa0

Please sign in to comment.