mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-22 15:32:10 +00:00
cache/dynacache: Don't mark all evicted items as stale
Limit that to the evicted items that matches the given change set. Currently this doesn't make any practical difference, but it would make the stale flag more general useful.
This commit is contained in:
parent
3d40aba512
commit
0d1f08a6cd
1 changed files with 11 additions and 9 deletions
20
cache/dynacache/dynacache.go
vendored
20
cache/dynacache/dynacache.go
vendored
|
@ -74,7 +74,6 @@ func New(opts Options) *Cache {
|
|||
evictedIdentities.Push(id)
|
||||
return false
|
||||
})
|
||||
resource.MarkStale(v)
|
||||
}
|
||||
|
||||
c := &Cache{
|
||||
|
@ -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
|
||||
|
@ -502,7 +498,14 @@ 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 {
|
||||
|
@ -510,9 +513,9 @@ func (p *Partition[K, V]) clearOnRebuild(changeset ...identity.Identity) {
|
|||
},
|
||||
),
|
||||
)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
return clear
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -586,7 +589,6 @@ type PartitionManager interface {
|
|||
const (
|
||||
ClearOnRebuild ClearWhen = iota + 1
|
||||
ClearOnChange
|
||||
ClearNever
|
||||
)
|
||||
|
||||
type ClearWhen int
|
||||
|
|
Loading…
Reference in a new issue