aboutsummaryrefslogtreecommitdiffhomepage
path: root/cache
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-06-08 11:52:22 +0200
committerBjørn Erik Pedersen <[email protected]>2024-06-23 11:25:47 +0200
commit6cd0784e447f18e009cbbf30de471e486f7cf356 (patch)
tree0684d05d7e487ebe93463636ed8b5a1bb78e4704 /cache
parent8731d8822216dd3c7587769e3cf5d98690717b0c (diff)
downloadhugo-6cd0784e447f18e009cbbf30de471e486f7cf356.tar.gz
hugo-6cd0784e447f18e009cbbf30de471e486f7cf356.zip
Implement defer
Closes #8086 Closes #12589
Diffstat (limited to 'cache')
-rw-r--r--cache/dynacache/dynacache.go18
-rw-r--r--cache/httpcache/httpcache.go1
2 files changed, 14 insertions, 5 deletions
diff --git a/cache/dynacache/dynacache.go b/cache/dynacache/dynacache.go
index 6190dd234..5007e27ba 100644
--- a/cache/dynacache/dynacache.go
+++ b/cache/dynacache/dynacache.go
@@ -38,6 +38,11 @@ import (
const minMaxSize = 10
+type KeyIdentity struct {
+ Key any
+ Identity identity.Identity
+}
+
// New creates a new cache.
func New(opts Options) *Cache {
if opts.CheckInterval == 0 {
@@ -64,14 +69,14 @@ func New(opts Options) *Cache {
infol := opts.Log.InfoCommand("dynacache")
- evictedIdentities := collections.NewStack[identity.Identity]()
+ evictedIdentities := collections.NewStack[KeyIdentity]()
onEvict := func(k, v any) {
if !opts.Watching {
return
}
identity.WalkIdentitiesShallow(v, func(level int, id identity.Identity) bool {
- evictedIdentities.Push(id)
+ evictedIdentities.Push(KeyIdentity{Key: k, Identity: id})
return false
})
resource.MarkStale(v)
@@ -124,7 +129,7 @@ type Cache struct {
partitions map[string]PartitionManager
onEvict func(k, v any)
- evictedIdentities *collections.Stack[identity.Identity]
+ evictedIdentities *collections.Stack[KeyIdentity]
opts Options
infol logg.LevelLogger
@@ -135,10 +140,15 @@ type Cache struct {
}
// DrainEvictedIdentities drains the evicted identities from the cache.
-func (c *Cache) DrainEvictedIdentities() []identity.Identity {
+func (c *Cache) DrainEvictedIdentities() []KeyIdentity {
return c.evictedIdentities.Drain()
}
+// DrainEvictedIdentitiesMatching drains the evicted identities from the cache that match the given predicate.
+func (c *Cache) DrainEvictedIdentitiesMatching(predicate func(KeyIdentity) bool) []KeyIdentity {
+ return c.evictedIdentities.DrainMatching(predicate)
+}
+
// ClearMatching clears all partition for which the predicate returns true.
func (c *Cache) ClearMatching(predicatePartition func(k string, p PartitionManager) bool, predicateValue func(k, v any) bool) {
if predicatePartition == nil {
diff --git a/cache/httpcache/httpcache.go b/cache/httpcache/httpcache.go
index ff360001f..98f7fedd4 100644
--- a/cache/httpcache/httpcache.go
+++ b/cache/httpcache/httpcache.go
@@ -83,7 +83,6 @@ func (c *Config) Compile() (ConfigCompiled, error) {
}
// PollConfig holds the configuration for polling remote resources to detect changes in watch mode.
-// TODO1 make sure this enabled only in watch mode.
type PollConfig struct {
// What remote resources to apply this configuration to.
For GlobMatcher