use correct context

This commit is contained in:
Kwitsch 2024-04-21 15:38:08 +00:00
parent afbb3053c3
commit 37fbb423b7
2 changed files with 4 additions and 4 deletions

View File

@ -103,14 +103,14 @@ func periodicCleanup[T any](ctx context.Context, c *ExpiringLRUCache[T]) {
for {
select {
case <-ticker.C:
c.cleanUp()
c.cleanUp(ctx)
case <-ctx.Done():
return
}
}
}
func (e *ExpiringLRUCache[T]) cleanUp() {
func (e *ExpiringLRUCache[T]) cleanUp(ctx context.Context) {
var expiredKeys []string
// check for expired items and collect expired keys
@ -126,7 +126,7 @@ func (e *ExpiringLRUCache[T]) cleanUp() {
var keysToDelete []string
for _, key := range expiredKeys {
newVal, newTTL := e.preExpirationFn(context.Background(), key)
newVal, newTTL := e.preExpirationFn(ctx, key)
if newVal != nil {
e.Put(key, newVal, newTTL)
} else {

View File

@ -181,7 +181,7 @@ var _ = Describe("Expiration cache", func() {
time.Sleep(2 * time.Millisecond)
// trigger cleanUp manually -> onExpiredFn will be executed, because element is expired
cache.cleanUp()
cache.cleanUp(ctx)
// wait for expiration
val, ttl := cache.Get("key1")