Skip to content

Commit

Permalink
Promoter that always inserts previously known keys
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dfinkel committed Jul 29, 2022
1 parent 511b4b6 commit a5a3ba1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions promoter/promoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a5a3ba1

Please sign in to comment.