mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 19:32:58 +00:00
Fix cache mutex lock (#1764)
This commit is contained in:
parent
505e4d77a7
commit
b9efc76722
12
middleware/cache/cache.go
vendored
12
middleware/cache/cache.go
vendored
@ -70,9 +70,8 @@ func New(config ...Config) fiber.Handler {
|
||||
// Get entry from pool
|
||||
e := manager.get(key)
|
||||
|
||||
// Lock entry and unlock when finished
|
||||
// Lock entry
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
|
||||
// Get timestamp
|
||||
ts := atomic.LoadUint64(×tamp)
|
||||
@ -105,15 +104,24 @@ func New(config ...Config) fiber.Handler {
|
||||
|
||||
c.Set(cfg.CacheHeader, cacheHit)
|
||||
|
||||
mux.Unlock()
|
||||
|
||||
// Return response
|
||||
return nil
|
||||
}
|
||||
|
||||
// make sure we're not blocking concurrent requests - do unlock
|
||||
mux.Unlock()
|
||||
|
||||
// Continue stack, return err to Fiber if exist
|
||||
if err := c.Next(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// lock entry back and unlock on finish
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
|
||||
// Don't cache response if Next returns true
|
||||
if cfg.Next != nil && cfg.Next(c) {
|
||||
c.Set(cfg.CacheHeader, cacheUnreachable)
|
||||
|
Loading…
x
Reference in New Issue
Block a user