cache

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Package cache implements interfaces for caches.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCacheMiss is returned if a Get failed because the item wasn't present.
	ErrCacheMiss = errors.New("cache: miss")

	// ErrNotStored is returned if conditional write (Add or Replace) failed because
	// the condition was not met.
	ErrNotStored = errors.New("cache: not stored")

	// Null is the null Cache instance.
	Null = &nullCache{}
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get gets the item for the given key.
	Get(k string) Item

	// GetMulti gets the items for the given keys.
	GetMulti(ks ...string) ([]Item, error)

	// Set sets the item in the cache.
	Set(k string, v interface{}, expire time.Duration) error

	// Add sets the item in the cache, but only if the key does not already exist.
	Add(k string, v interface{}, expire time.Duration) error

	// Replace sets the item in the cache, but only if the key already exists.
	Replace(k string, v interface{}, expire time.Duration) error

	// Delete deletes the item with the given key.
	Delete(k string) error

	// Inc increments a key by the Value.
	Inc(k string, v uint64) (int64, error)

	// Dec decrements a key by the Value.
	Dec(k string, v uint64) (int64, error)
}

Cache represents a cache instance.

type Decoder

type Decoder interface {
	Bool(interface{}) (bool, error)
	Bytes(interface{}) ([]byte, error)
	Int64(interface{}) (int64, error)
	Uint64(interface{}) (uint64, error)
	Float64(interface{}) (float64, error)
	String(interface{}) (string, error)
}

Decoder represents a value decoder.

type Item

type Item struct {
	Value interface{}
	Err   error
	// contains filtered or unexported fields
}

Item represents an item to be returned or stored in the cache.

func NewItem

func NewItem(d Decoder, v interface{}, err error) Item

NewItem creates a new Item.

func (Item) Bool

func (i Item) Bool() (bool, error)

Bool gets the cache items Value as a bool, or and error.

func (Item) Bytes

func (i Item) Bytes() ([]byte, error)

Bytes gets the cache items Value as bytes.

func (Item) Float64

func (i Item) Float64() (float64, error)

Float64 gets the cache items Value as a float64, or and error.

func (Item) Int64

func (i Item) Int64() (int64, error)

Int64 gets the cache items Value as an int64, or and error.

func (Item) String

func (i Item) String() (string, error)

Bytes gets the cache items Value as a string.

func (Item) Uint64

func (i Item) Uint64() (uint64, error)

Uint64 gets the cache items Value as a uint64, or and error.

Jump to

Keyboard shortcuts

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