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

cache/dynacache: Don't mark all evicted items as stale #12446

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
20 changes: 11 additions & 9 deletions cache/dynacache/dynacache.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func New(opts Options) *Cache {
evictedIdentities.Push(id)
return false
})
resource.MarkStale(v)
}

c := &Cache{
Expand Down Expand Up @@ -458,11 +457,8 @@ func (p *Partition[K, V]) clearMatching(predicate func(k, v any) bool) {

func (p *Partition[K, V]) clearOnRebuild(changeset ...identity.Identity) {
opts := p.getOptions()
if opts.ClearWhen == ClearNever {
return
}

if opts.ClearWhen == ClearOnRebuild {
if opts.ClearWhen == ClearOnRebuild && len(changeset) == 0 {
// Clear all.
p.Clear()
return
Expand Down Expand Up @@ -502,17 +498,24 @@ func (p *Partition[K, V]) clearOnRebuild(changeset ...identity.Identity) {
// Second pass needs to be done in a separate loop to catch any
// elements marked as stale in the other partitions.
p.c.DeleteFunc(func(key K, v V) bool {
if shouldDelete(key, v) {
match := shouldDelete(key, v)
clear := match || opts.ClearWhen == ClearOnRebuild

if match {
resource.MarkStale(v)
}

if clear {
p.trace.Log(
logg.StringFunc(
func() string {
return fmt.Sprintf("first pass: clearing cache key %v", key)
},
),
)
return true
}
return false

return clear
})
}

Expand Down Expand Up @@ -586,7 +589,6 @@ type PartitionManager interface {
const (
ClearOnRebuild ClearWhen = iota + 1
ClearOnChange
ClearNever
)

type ClearWhen int
Expand Down
Loading