memcache

package module
v2.0.0-...-1948240 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

func NewCache

func NewCache(opts ...Option) *Cache

NewCache returns a new Memcache-backed Cache. The optional opts override the default configuration.

func (*Cache) AddPrefix

func (c *Cache) AddPrefix(key string) string

AddPrefix returns key prefixed with the cache's key prefix.

func (*Cache) Client

func (c *Cache) Client() any

Client returns the underlying Memcache client.

func (*Cache) Close

func (c *Cache) Close() (err error)

Close closes the cache. It reports errors.ErrCacheClosed when the cache is already closed. The built-in client is closed only when it was created by NewCache.

func (*Cache) DecrFloat

func (c *Cache) DecrFloat(ctx context.Context, key string, value float64) (float64, error)

DecrFloat decrements the float stored at key by value and returns the resulting value. Since Memcache does not support floats, the decrement is implemented through integer decrements.

func (*Cache) DecrInt

func (c *Cache) DecrInt(ctx context.Context, key string, value int64) (int64, error)

DecrInt decrements the integer stored at key by value and returns the resulting value.

func (*Cache) Delete

func (c *Cache) Delete(ctx context.Context, keys ...string) (int64, error)

Delete removes the given keys and reports how many keys were actually deleted.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string, def ...any) cache.Result

Get returns the value of key. The optional def is returned when the entry does not exist.

func (*Cache) GetSet

func (c *Cache) GetSet(ctx context.Context, key string, fn cache.SetValueFunc) cache.Result

GetSet returns the value of key, generating it with fn and storing it when the entry does not exist.

func (*Cache) Has

func (c *Cache) Has(ctx context.Context, key string) (bool, error)

Has reports whether the entry identified by key exists.

func (*Cache) IncrFloat

func (c *Cache) IncrFloat(ctx context.Context, key string, value float64) (float64, error)

IncrFloat increments the float stored at key by value and returns the resulting value. Since Memcache does not support floats, the increment is implemented through integer increments.

func (*Cache) IncrInt

func (c *Cache) IncrInt(ctx context.Context, key string, value int64) (int64, error)

IncrInt increments the integer stored at key by value and returns the resulting value.

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, key string, value any, expiration ...time.Duration) error

Set stores value under key. The optional expiration sets the entry's time to live; when it is omitted a random duration within the configured expiration range is used.

type Option

type Option func(o *options)

func WithAddrs

func WithAddrs(addrs ...string) Option

WithAddrs sets the connection addresses. It accepts one or more Memcache node addresses.

func WithClient

func WithClient(client *memcache.Client) Option

WithClient sets an external client. The external client takes precedence over the built-in one.

func WithMaxExpiration

func WithMaxExpiration(maxExpiration time.Duration) Option

WithMaxExpiration sets the maximum expiration time. Non-positive values are ignored.

func WithMinExpiration

func WithMinExpiration(minExpiration time.Duration) Option

WithMinExpiration sets the minimum expiration time. Non-positive values are ignored.

func WithNilExpiration

func WithNilExpiration(nilExpiration time.Duration) Option

WithNilExpiration sets the expiration time of a cached nil. Non-positive values are ignored.

func WithNilValue

func WithNilValue(nilValue string) Option

WithNilValue sets the placeholder value that marks a cached nil.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets the key prefix.

Jump to

Keyboard shortcuts

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