cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 36 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	FlagLogLevel       = "log_level"
	FlagMetricsAddress = "metrics_address"
)
View Source
const (
	DbValueConfirmationAttempts = 5
	SEP                         = ";"
	// CompressionThreshold is the minimum data size (in bytes) before gzip is attempted.
	CompressionThreshold = 1024
)
View Source
const (
	ExpirationFlagName                           = "expiration"
	ExpirationTimeFinalizedMultiplierFlagName    = "expiration-multiplier"
	ExpirationNonFinalizedFlagName               = "expiration-non-finalized"
	ExpirationTimeNonFinalizedMultiplierFlagName = "expiration-non-finalized-multiplier"
	ExpirationBlocksHashesToHeightsFlagName      = "expiration-blocks-hashes-to-heights"
	ExpirationNodeErrorsOnFinalizedFlagName      = "expiration-finalized-node-errors"
	FlagCacheSizeName                            = "max-items"
	DefaultExpirationForNonFinalized             = 500 * time.Millisecond
	DefaultExpirationTimeFinalizedMultiplier     = 1.0
	DefaultExpirationTimeNonFinalizedMultiplier  = 1.0
	DefaultExpirationBlocksHashesToHeights       = 48 * time.Hour
	DefaultExpirationTimeFinalized               = time.Hour
	DefaultExpirationNodeErrors                  = 250 * time.Millisecond
	CacheNumCounters                             = 100000000 // expect 10M items

)
View Source
const (
	DisabledFlagOption = "disabled"
)

Variables

View Source
var (
	NotFoundError     = errors.New("cache entry for specific block and request wasn't found")
	HashMismatchError = errors.New("cache entry for specific block and request had a mismatching hash stored")
	EntryTypeError    = errors.New("cache entry for specific block and request had a mismatching object stored")
)

Functions

func CreateCacheCobraCommand

func CreateCacheCobraCommand() *cobra.Command

func Server

func Server(
	ctx context.Context,
	listenAddr string,
	metricsAddr string,
	flags *pflag.FlagSet,
)

Types

type CacheMetrics

type CacheMetrics struct {
	// contains filtered or unexported fields
}

func NewCacheMetricsServer

func NewCacheMetricsServer(listenAddress string) *CacheMetrics

func (*CacheMetrics) AddApiSpecific

func (c *CacheMetrics) AddApiSpecific(block int64, chainId string, hit bool)

func (*CacheMetrics) AddExpired

func (c *CacheMetrics) AddExpired()

func (*CacheMetrics) SetCacheSize

func (c *CacheMetrics) SetCacheSize(size int64)

type CacheServer

type CacheServer struct {
	ExpirationFinalized             time.Duration
	ExpirationNonFinalized          time.Duration
	ExpirationNodeErrors            time.Duration
	ExpirationBlocksHashesToHeights time.Duration

	CacheMetrics *CacheMetrics
	CacheMaxCost int64
	// contains filtered or unexported fields
}

func (*CacheServer) ExpirationForChain

func (cs *CacheServer) ExpirationForChain(averageBlockTimeForChain time.Duration) time.Duration

func (*CacheServer) GetTotalCacheSize

func (cs *CacheServer) GetTotalCacheSize() int64

func (*CacheServer) InitCache

func (cs *CacheServer) InitCache(
	ctx context.Context,
	expiration time.Duration,
	expirationNonFinalized time.Duration,
	expirationNodeErrorsOnFinalized time.Duration,
	expirationBlocksHashesToHeights time.Duration,
	metricsAddr string,
	expirationFinalizedMultiplier float64,
	expirationNonFinalizedMultiplier float64,
)

func (*CacheServer) Serve

func (cs *CacheServer) Serve(ctx context.Context, listenAddr string)

type CacheValue

type CacheValue struct {
	Response         relaytypes.RelayReply
	Hash             []byte
	OptionalMetadata []relaytypes.Metadata
	SeenBlock        int64
	IsCompressed     bool
}

func (*CacheValue) Cost

func (cv *CacheValue) Cost() int64

func (*CacheValue) ToCacheReply

func (cv *CacheValue) ToCacheReply() *relaytypes.CacheRelayReply

type LastestCacheStore

type LastestCacheStore struct {
	// contains filtered or unexported fields
}

func (*LastestCacheStore) Cost

func (cv *LastestCacheStore) Cost() int64

type RelayerCacheServer

type RelayerCacheServer struct {
	relaytypes.UnimplementedRelayerCacheServer
	CacheServer *CacheServer
	// contains filtered or unexported fields
}

func (*RelayerCacheServer) FlushCache

func (s *RelayerCacheServer) FlushCache(ctx context.Context, req *emptypb.Empty) (*emptypb.Empty, error)

FlushCache empties every Ristretto store on this cache server. Reached only from the smart router's /debug/reset-all handler so black-box tests can drop stale entries without restarting the pod. Ristretto's Clear() is not atomic and assumes no concurrent Set/Get; Wait() drains the asynchronous Set buffer so a Set in flight at Clear time can't survive the flush and serve a hit on the next Get. Caveat: this guarantee only holds when the test framework stops issuing relay traffic before calling /debug/reset-all — a concurrent Set buffered during the Clear/Wait window can still resurface as a hit after Wait returns. Production callers (the simulator harness) honour that invariant by design.

func (*RelayerCacheServer) GetRelay

func (*RelayerCacheServer) Health

func (*RelayerCacheServer) PrintCacheStats

func (s *RelayerCacheServer) PrintCacheStats(ctx context.Context, desc string)

func (*RelayerCacheServer) SetRelay

func (s *RelayerCacheServer) SetRelay(ctx context.Context, relayCacheSet *relaytypes.RelayCacheSet) (*emptypb.Empty, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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