mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-25 23:03:47 +01:00
chore: fixes race condition (#2959)
This commit is contained in:
4
internal/cache/expire.go
vendored
4
internal/cache/expire.go
vendored
@@ -1,6 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -11,6 +12,7 @@ type Cache[T any] struct {
|
||||
Timestamp time.Time
|
||||
Duration time.Duration
|
||||
Data T
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func New[T any](f func() (T, error), duration time.Duration) *Cache[T] {
|
||||
@@ -21,6 +23,8 @@ func New[T any](f func() (T, error), duration time.Duration) *Cache[T] {
|
||||
}
|
||||
|
||||
func (c *Cache[T]) GetWithHit() (T, error, bool) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
hit := true
|
||||
if c.Timestamp.IsZero() || time.Since(c.Timestamp) > c.Duration {
|
||||
hit = false
|
||||
|
||||
Reference in New Issue
Block a user