memory

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultExpiration is the default duration for items stored in
	// the cache to expire.
	DefaultExpiration time.Duration = 0
	// ErrItemExpired is returned in Cache.Get when the item found in the cache
	// has expired.
	ErrItemExpired error = errors.InternalServer("ErrItemExpired", "item has expired")
	// ErrKeyNotFound is returned in Cache.Get and Cache.Delete when the
	// provided key could not be found in cache.
	ErrKeyNotFound error = errors.InternalServer("ErrKeyNotFound", "key not found in cache")
)
View Source
var (
	// DefaultCache is the default cache.
	DefaultCache cache.Cache = NewCache()
)

Functions

func NewCache

func NewCache(opts ...Option) *memCache

NewCache returns a new cache.

Types

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(o *Options)

Option manipulates the Options passed.

func Expiration

func Expiration(d time.Duration) Option

Expiration sets the duration for items stored in the cache to expire.

func Items

func Items(i map[string]Item) Option

Items initializes the cache with preconfigured items.

func WithAddress

func WithAddress(addr string) Option

WithAddress sets the cache service address or connection information

func WithContext

func WithContext(c context.Context) Option

WithContext sets the cache context, for any extra configuration

type Options

type Options struct {
	Expiration time.Duration
	Items      map[string]Item
	// Address represents the address or other connection information of the cache service.
	Address string
	// Context should contain all implementation specific options, using context.WithValue.
	Context context.Context
}

Options represents the options for the cache.

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions returns a new options struct.

Jump to

Keyboard shortcuts

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