Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefetch syncs to redis #1446

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cache/expirationcache/expiration_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cache/expirationcache/expiration_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading