From a5a3ba11b7221135e394fde55e4a9d59345f8537 Mon Sep 17 00:00:00 2001 From: David Finkel Date: Fri, 29 Jul 2022 15:57:06 -0400 Subject: [PATCH] Promoter that always inserts previously known keys A la ARC, any second reference to a key that's present in the candidate cache gets it inserted into the hotcache. This way a key that gets a short burst of requests is always added to the hotcache. The candidate-cache is generally not large enough that anything will hang out in it for a long time anyway. After some testing, this promoter is likely to become the default. --- promoter/promoter.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/promoter/promoter.go b/promoter/promoter.go index b1f09e5f..055923b3 100644 --- a/promoter/promoter.go +++ b/promoter/promoter.go @@ -75,3 +75,15 @@ type DefaultPromoter struct{} func (p *DefaultPromoter) ShouldPromote(key string, data []byte, stats Stats) bool { return stats.KeyQPS >= stats.HCStats.LeastRecentQPS } + +// PreviouslyKnownPromoter implements Promoter and promotes the given key if +// the key has been seen before (was previously present in the candidate cache). +type PreviouslyKnownPromoter struct{} + +// ShouldPromote for the PreviouslyKnownPromoter promotes if the Hits value is +// non-zero, indicating that the key has been seen before. +func (p *PreviouslyKnownPromoter) ShouldPromote(key string, data []byte, stats Stats) bool { + // stats.Hits is explicitly documented to be zero if this is the first + // hit for the key (that this Galaxy knows of) + return stats.Hits > 0 +}