memory

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memory

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

func New

func New(expiration time.Duration, cleanup time.Duration) *Memory

func (*Memory) Decrement

func (m *Memory) Decrement(ctx context.Context, key string, by int64) (int64, error)

Decrement atomically decreases the integer value stored at key by the given amount.

func (*Memory) Delete

func (m *Memory) Delete(_ context.Context, key string) error

Delete removes the cached value for the given key.

func (*Memory) Forever

func (m *Memory) Forever(_ context.Context, key string, value any) error

Forever stores a value permanently (no TTL).

func (*Memory) Get

func (m *Memory) Get(_ context.Context, key string) (any, error)

Get retrieves the value for the given key.

func (*Memory) Has

func (m *Memory) Has(_ context.Context, key string) (bool, error)

Has returns true if the key exists in the cache and is not expired.

func (*Memory) Increment

func (m *Memory) Increment(ctx context.Context, key string, by int64) (int64, error)

Increment atomically increases the integer value stored at key by the given amount.

func (*Memory) Pull

func (m *Memory) Pull(ctx context.Context, key string) (any, error)

Pull retrieves and removes the value for the given key.

func (*Memory) Put

func (m *Memory) Put(_ context.Context, key string, value any, ttl time.Duration) error

Put stores a value for the given key with a TTL.

func (*Memory) Remember

func (m *Memory) Remember(ctx context.Context, key string, ttl time.Duration, compute func() (any, error)) (any, error)

Remember tries to get the value or compute and store it if not found.

func (*Memory) RememberForever

func (m *Memory) RememberForever(ctx context.Context, key string, compute func() (any, error)) (any, error)

RememberForever tries to get the value or compute and store it forever if not found.

Jump to

Keyboard shortcuts

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