cache

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: MIT Imports: 3 Imported by: 0

README

Logo

Go Report Card Build Status Coverage Status GoDoc GitHub release GitHub license

Go cache adapters

Overview

Install with:

go get github.com/hamba/cache

Documentation

Overview

Package cache is an abstraction for cache clients.

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(ctx context.Context, k string) Item

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

	// Set sets the item in the cache.
	Set(ctx context.Context, 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(ctx context.Context, k string, v interface{}, expire time.Duration) error

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

	// Delete deletes the item with the given key.
	Delete(ctx context.Context, k string) error

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

	// Dec decrements a key by the Value.
	Dec(ctx context.Context, 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)

String 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.

Directories

Path Synopsis
internal
decoder
Package decoder implements cache decoders.
Package decoder implements cache decoders.
Package memcache implements a memcache adapter for github.com/hamba/pkg/cache.
Package memcache implements a memcache adapter for github.com/hamba/pkg/cache.
Package redis implements a redis adapter for github.com/hamba/pkg/cache.
Package redis implements a redis adapter for github.com/hamba/pkg/cache.

Jump to

Keyboard shortcuts

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