Help us shape the future of Go! Take the 2026 Go Developer Survey

promoter

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultPromoter

type DefaultPromoter struct{}

DefaultPromoter promotes if the given key QPS is higher than the QPS of the least recently accessed element in the hotcache

func (*DefaultPromoter) ShouldPromote

func (p *DefaultPromoter) ShouldPromote(key string, data []byte, stats Stats) bool

ShouldPromote for a DefaultPromoter promotes if the given key QPS is higher than the QPS of the least recently accessed element in the hotcache

type Func

type Func func(key string, data []byte, stats Stats) bool

Func implements Promoter with a function.

func (Func) ShouldPromote

func (f Func) ShouldPromote(key string, data []byte, stats Stats) bool

ShouldPromote returns true if the given key/data pair has been chosen to add to the hotcache

type HCStats

type HCStats struct {
	MostRecentQPS  float64
	LeastRecentQPS float64
	HCSize         int64
	HCCapacity     int64
}

HCStats keeps track of the size, capacity, and coldest/hottest elements in the hot cache

type Interface

type Interface interface {
	ShouldPromote(key string, data []byte, stats Stats) bool
}

Interface is the interface for determining whether a key/value pair should be added to the hot cache

type PreviouslyKnownPromoter

type PreviouslyKnownPromoter struct{}

PreviouslyKnownPromoter implements Promoter and promotes the given key if the key has been seen before (was previously present in the candidate cache).

func (*PreviouslyKnownPromoter) ShouldPromote

func (p *PreviouslyKnownPromoter) ShouldPromote(key string, data []byte, stats Stats) bool

ShouldPromote for the PreviouslyKnownPromoter promotes if the Hits value is non-zero, indicating that the key has been seen before.

type ProbabilisticPromoter

type ProbabilisticPromoter struct {
	ProbDenominator int
}

ProbabilisticPromoter promotes based on a 1/ProbDenominator chance

func (*ProbabilisticPromoter) ShouldPromote

func (p *ProbabilisticPromoter) ShouldPromote(key string, data []byte, stats Stats) bool

ShouldPromote for a ProbabilisticPromoter promotes based on a 1/ProbDenominator chance

type Stats

type Stats struct {
	// Request-rate for this key (possibly with some windowing applied)
	KeyQPS float64
	// Number of hits for this key (also possibly with some windowing applied)
	// This will be zero if there is no record of this key (not seen before
	// or tracking expired)
	Hits    int64
	HCStats *HCStats
}

Stats contains both the KeyQPS and a pointer to the galaxy-wide HCStats

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL