memory

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package memory provides a bounded, concurrency-safe LRU cache backend.

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 bounded concurrency-safe LRU backend.

func New

func New(config Config) (*Backend, error)

New validates config and constructs an empty memory backend.

func (*Backend) Close

func (b *Backend) Close() error

Close releases retained entries and rejects subsequent operations.

func (*Backend) Delete

func (b *Backend) Delete(ctx context.Context, key string) (bool, error)

Delete removes key and reports whether it was present.

func (*Backend) Get

func (b *Backend) Get(ctx context.Context, key string) (cache.Record, bool, error)

Get returns a cloned live record or an explicit miss.

func (*Backend) Set

func (b *Backend) Set(
	ctx context.Context,
	key string,
	record cache.Record,
	condition cache.Condition,
) (bool, error)

Set atomically applies condition and stores a cloned record.

func (*Backend) Stats

func (b *Backend) Stats() Stats

Stats returns a synchronized snapshot of backend counters.

type Config

type Config struct {
	MaxEntries int
	MaxBytes   int
	Clock      cache.Clock
	Observer   cache.Observer
}

Config defines hard entry and retained-byte limits for a Backend.

type Stats

type Stats struct {
	Entries     int
	Bytes       int
	Evictions   uint64
	Expirations uint64
}

Stats is a snapshot of retained state and cumulative removals.

Jump to

Keyboard shortcuts

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