memory

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package memory provides a simple concurrent in-memory cache with TTL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache is a plain map-backed cache (no eviction besides TTL).

func New

func New[K comparable, V any](opts ...Option) *Cache[K, V]

New creates a memory cache.

func (*Cache[K, V]) Clear

func (c *Cache[K, V]) Clear(ctx context.Context) error

func (*Cache[K, V]) Close

func (c *Cache[K, V]) Close() error

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(ctx context.Context, key K) error

func (*Cache[K, V]) Exists

func (c *Cache[K, V]) Exists(ctx context.Context, key K) (bool, error)

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(ctx context.Context, key K) (V, error)

func (*Cache[K, V]) Len

func (c *Cache[K, V]) Len() int

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(ctx context.Context, key K, value V, ttl time.Duration) error

type Option

type Option func(*config)

Option configures a memory cache.

func WithCleanupInterval

func WithCleanupInterval(d time.Duration) Option

WithCleanupInterval sets expired-entry purge interval. 0 disables background GC.

func WithDefaultTTL

func WithDefaultTTL(ttl time.Duration) Option

WithDefaultTTL sets the default TTL used when Set is called with ttl == 0.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets a key prefix.

Jump to

Keyboard shortcuts

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