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

local

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package local is a bounded in-process cache.Store, for development, tests and single-process deployments. It is per process: another instance has its own, and a restart empties it.

It never grows past its limits. When it is full it first drops entries that have already expired, then the least recently used. There is no background goroutine and nothing to start or stop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxEntries is the most entries held. It must be positive.
	MaxEntries int
	// MaxBytes, when positive, is the most bytes held, counting each entry's
	// full key plus its value. Zero means no byte budget; negative is
	// invalid.
	MaxBytes int64
	// Now is the clock; nil means time.Now. Tests set it to control expiry.
	Now func() time.Time
}

Config bounds a Store. MaxEntries is required.

type Store

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

Store is a bounded in-memory cache.Store.

func New

func New(cfg Config) (*Store, error)

New returns an empty Store bounded by cfg.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete implements cache.Store.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) ([]byte, bool, error)

Get implements cache.Store.

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set implements cache.Store. It returns cache.ErrTooLarge, leaving the cache untouched, for an entry whose key and value alone exceed MaxBytes.

Jump to

Keyboard shortcuts

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