cache

package
v0.0.0-...-ca36184 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultCache is the default cache.
	DefaultCache Cache = NewCache()

	// DefaultExpiration is the default duration for items stored in the cache to expire.
	DefaultExpiration time.Duration = 0

	ErrItemExpired = errors.New("item has expired")

	ErrKeyNotFound = errors.New("key not found in cache")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) (interface{}, time.Time, error)
	Set(ctx context.Context, key string, value interface{}, d time.Duration) error
	Del(ctx context.Context, key string) error
}

Cache is the interface that wraps the cache.

func NewCache

func NewCache(opts ...Option) Cache

NewCache returns a new cache.

type Item

type Item struct {
	Value      interface{}
	Expiration int64
}

Item represents an item stored in the cache.

func (*Item) Expired

func (i *Item) Expired() bool

Expired returns true if the item has expired.

type Option

type Option func(*Options)

func WithAddress

func WithAddress(addr string) Option

WithAddress sets the cache service address or connection information.

func WithExpiration

func WithExpiration(d time.Duration) Option

func WithItems

func WithItems(i map[string]Item) Option

type Options

type Options struct {
	Expiration time.Duration
	Items      map[string]Item
	Address    string
}

Options represents the options for the cache.

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions returns a new options struct.

Directories

Path Synopsis
plugin
memory module

Jump to

Keyboard shortcuts

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