cache

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultInMemCacheCapacity = 10000

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Set adds the trace to the cache. If it is kicking out a trace from the cache
	// that has not yet been sent, it will return that trace. Otherwise returns nil.
	Set(trace *types.Trace) *types.Trace
	Get(traceID string) *types.Trace
	// GetAll is used during shutdown to get all in-flight traces to flush them
	GetAll() []*types.Trace

	// Retrieve and remove all traces which are past their SendBy date.
	// Does not check whether they've been sent.
	TakeExpiredTraces(now time.Time) []*types.Trace
}

Cache is a non-threadsafe cache. It must not be used for concurrent access.

type DefaultInMemCache

type DefaultInMemCache struct {
	Metrics metrics.Metrics
	Logger  logger.Logger
	// contains filtered or unexported fields
}

DefaultInMemCache keeps a bounded number of entries to avoid growing memory forever. Traces are expunged from the cache in insertion order (not access order) so it is important to have a cache larger than trace throughput * longest trace.

func NewInMemCache

func NewInMemCache(
	capacity int,
	metrics metrics.Metrics,
	logger logger.Logger,
) *DefaultInMemCache

func (*DefaultInMemCache) Get

func (d *DefaultInMemCache) Get(traceID string) *types.Trace

func (*DefaultInMemCache) GetAll

func (d *DefaultInMemCache) GetAll() []*types.Trace

GetAll is not thread safe and should only be used when that's ok Returns all non-nil trace entries.

func (*DefaultInMemCache) GetCacheSize

func (d *DefaultInMemCache) GetCacheSize() int

func (*DefaultInMemCache) Set

func (d *DefaultInMemCache) Set(trace *types.Trace) *types.Trace

Set adds the trace to the ring. If it is kicking out a trace from the ring that has not yet been sent, it will return that trace. Otherwise returns nil.

func (*DefaultInMemCache) TakeExpiredTraces

func (d *DefaultInMemCache) TakeExpiredTraces(now time.Time) []*types.Trace

Jump to

Keyboard shortcuts

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