cache

package
v0.0.0-...-9a2c5cd Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Key = attribute.Key("cache.key")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a cache for working set entries.

The cache evicts inactive entries after the given expireDuration. Recently accessed entries survive expireDuration.

func New

func New(cfg *config.Cache) (*Cache, error)

New creates new cache with the given maxBytes capacity in bytes and *cacheExpireDuration expiration.

Stop must be called on the returned cache when it is no longer needed.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, k []byte) []byte

func (*Cache) Has

func (c *Cache) Has(k []byte) bool

Has verifies whether the cache contains the given key.

func (*Cache) Remove

func (c *Cache) Remove(ctx context.Context, k []byte) error

func (*Cache) Reset

func (c *Cache) Reset()

Reset resets the cache.

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, k []byte, v []byte)

Set sets the given value for the given key.

func (*Cache) Stop

func (c *Cache) Stop()

Stop stops the cache.

The cache cannot be used after the Stop call.

func (*Cache) UpdateStats

func (c *Cache) UpdateStats(fcs *fastcache.Stats)

UpdateStats updates fcs with cache stats.

type KeyScope

type KeyScope[V any] interface {
	Get(ctx context.Context) (V, bool)
	Set(ctx context.Context, value V)
	Delete(ctx context.Context)

	GetMany(ctx context.Context) ([]*V, bool)
	SetMany(ctx context.Context, value []*V)
}

type Manager

type Manager interface {
	Get(ctx context.Context, k []byte) []byte
	Set(ctx context.Context, k []byte, v []byte)
	Remove(ctx context.Context, k []byte) error
	Has(k []byte) bool

	Stop()
	Reset()
	UpdateStats(fcs *fastcache.Stats)
}

type Mode

type Mode int
const (
	Split Mode = iota
	Switching
	Whole
)

Cache modes.

type Scope

type Scope[V any] struct {
	// contains filtered or unexported fields
}

Scope represents a set of cache keys, each containing an unordered set of values of type V.

func NewScope

func NewScope[V any](cache Manager, scope string) *Scope[V]

func (*Scope[V]) Key

func (ks *Scope[V]) Key(domain, id int64, args ...any) KeyScope[V]

type Tracer

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

func NewTracer

func NewTracer() *Tracer

func (*Tracer) End

func (t *Tracer) End(ctx context.Context, err error)

func (*Tracer) Start

func (t *Tracer) Start(ctx context.Context, op, k string) context.Context

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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