mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 14:10:31 +03:00
Make the cache eviction logic for stale entities more robust
Fixes #12458
This commit is contained in:
parent
68e95327f7
commit
503d20954f
12 changed files with 157 additions and 55 deletions
|
@ -296,16 +296,19 @@ type hashProvider interface {
|
|||
hash() string
|
||||
}
|
||||
|
||||
var _ resource.StaleInfo = (*StaleValue[any])(nil)
|
||||
|
||||
type StaleValue[V any] struct {
|
||||
// The value.
|
||||
Value V
|
||||
|
||||
// IsStaleFunc reports whether the value is stale.
|
||||
IsStaleFunc func() bool
|
||||
// StaleVersionFunc reports the current version of the value.
|
||||
// This always starts out at 0 and get incremented on staleness.
|
||||
StaleVersionFunc func() uint32
|
||||
}
|
||||
|
||||
func (s *StaleValue[V]) IsStale() bool {
|
||||
return s.IsStaleFunc()
|
||||
func (s *StaleValue[V]) StaleVersion() uint32 {
|
||||
return s.StaleVersionFunc()
|
||||
}
|
||||
|
||||
type AtomicStaler struct {
|
||||
|
@ -313,11 +316,11 @@ type AtomicStaler struct {
|
|||
}
|
||||
|
||||
func (s *AtomicStaler) MarkStale() {
|
||||
atomic.StoreUint32(&s.stale, 1)
|
||||
atomic.AddUint32(&s.stale, 1)
|
||||
}
|
||||
|
||||
func (s *AtomicStaler) IsStale() bool {
|
||||
return atomic.LoadUint32(&(s.stale)) > 0
|
||||
func (s *AtomicStaler) StaleVersion() uint32 {
|
||||
return atomic.LoadUint32(&(s.stale))
|
||||
}
|
||||
|
||||
// For internal use.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue