memory

package
v0.13.6 Latest Latest
Warning

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

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

Documentation

Overview

Package memory provides an in-process [cache.Backend]: zero infrastructure, used for dev/CI and for per-instance frame storage in the retry endpoint. It offers no cross-instance coordination — SetNX races are resolved only within this process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

Backend is a striped in-memory cache. The keyspace is sharded across independently-locked maps so concurrent workers do not serialise on a single mutex.

func New

func New(maxKeys int) *Backend

New constructs an in-memory backend with the given soft key cap (0 = unbounded). The cap is enforced per shard (maxKeys/shardCount) with simple oldest-wins eviction, which is sufficient for the bounded TTL workloads here.

func (*Backend) Close

func (b *Backend) Close() error

Close stops the background GC. Safe to call multiple times.

func (*Backend) Del

func (b *Backend) Del(_ context.Context, key []byte) error

Del removes key.

func (*Backend) Get

func (b *Backend) Get(_ context.Context, key []byte) ([]byte, error)

Get returns the live value for key, or (nil, nil) on miss/expiry.

func (*Backend) Healthy

func (b *Backend) Healthy(_ context.Context) bool

Healthy always reports true for the in-memory backend.

func (*Backend) Len

func (b *Backend) Len() int

Len reports the current entry count across all shards (including expired entries not yet swept). Used by the retry endpoint's cache-size sampler.

func (*Backend) Set

func (b *Backend) Set(_ context.Context, key, val []byte, ttl time.Duration) error

Set unconditionally writes key=val.

func (*Backend) SetNX

func (b *Backend) SetNX(_ context.Context, key, val []byte, ttl time.Duration) (bool, error)

SetNX creates key=val iff absent (or its prior entry has expired).

Jump to

Keyboard shortcuts

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