kvCache

package
v0.0.0-...-50e54af Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheMiss = errors.New("cache: key is missing")
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	c3.RedisLock
	// contains filtered or unexported fields
}

func New

func New(opt *Options) *Cache

func (*Cache) Delete

func (cd *Cache) Delete(ctx context.Context, key string) error

func (*Cache) DeleteFromLocalCache

func (cd *Cache) DeleteFromLocalCache(key string)

func (*Cache) Exists

func (cd *Cache) Exists(ctx context.Context, key string) bool

Exists reports whether value for the given key exists.

func (*Cache) Get

func (cd *Cache) Get(ctx context.Context, key string, value interface{}) error

Get gets the value for the given key.

func (*Cache) GetS

func (cd *Cache) GetS(ctx context.Context, keys []string, skipLocalCache bool) ([][]byte, error)

func (*Cache) GetSkippingLocalCache

func (cd *Cache) GetSkippingLocalCache(
	ctx context.Context, key string, value interface{},
) error

Get gets the value for the given key skipping local cache.

func (*Cache) Marshal

func (cd *Cache) Marshal(value interface{}) ([]byte, error)

func (*Cache) Once

func (cd *Cache) Once(item *Item) error

Once gets the item.Value for the given item.Key from the cache or executes, caches, and returns the results of the given item.Func, making sure that only one execution is in-flight for a given item.Key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results.

func (*Cache) Set

func (cd *Cache) Set(item *Item) error

Set caches the item.

func (*Cache) SetS

func (cd *Cache) SetS(ctx context.Context, items []*Item) error

func (*Cache) Unmarshal

func (cd *Cache) Unmarshal(b []byte, value interface{}) error

type Item

type Item struct {
	Ctx context.Context

	Key   string
	Value interface{}

	// TTL is the cache expiration time.
	// Default TTL is 1 hour.
	TTL time.Duration

	// Do returns value to be cached.
	Do func(*Item) (interface{}, error)

	// SetXX only sets the key if it already exists.
	SetXX bool

	// SetNX only sets the key if it does not already exist.
	SetNX bool

	// SkipLocalCache skips local cache as if it is not set.
	SkipLocalCache bool
}

func (*Item) Context

func (item *Item) Context() context.Context

type MarshalFunc

type MarshalFunc func(interface{}) ([]byte, error)

type Options

type Options struct {
	Redis        c3.Rediser
	LocalCache   c3.LocalCache
	StatsEnabled bool
	Marshal      MarshalFunc
	Unmarshal    UnmarshalFunc
}

type UnmarshalFunc

type UnmarshalFunc func([]byte, interface{}) error

Jump to

Keyboard shortcuts

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