cache

package module
v0.0.0-...-e139633 Latest Latest
Warning

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

Go to latest
Published: May 15, 2021 License: MIT Imports: 6 Imported by: 3

README

EasyCache

业务标准缓存层

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMiss = errors.New("cache miss")

Functions

This section is empty.

Types

type CodecInterface

type CodecInterface interface {
	Encode(val interface{}) ([]byte, error)
	Decode(bts []byte, dest interface{}) error
}

CodecInterface 编码接口

func JsonCodec

func JsonCodec() CodecInterface

type DriverInterface

type DriverInterface interface {
	Get(key string) ([]byte, bool, error)
	Set(key string, val []byte, ttl time.Duration) error
	Del(key string) error
}

DriverInterface 驱动接口

func MapDriver

func MapDriver() DriverInterface

func NullDriver

func NullDriver() DriverInterface

type Interface

type Interface interface {
	Has(key string) error
	Get(key string, dest interface{}) error
	Set(key string, val interface{}, ttl time.Duration) error
	Del(key string) error
	SetOrDel(key string, val interface{}, ttl time.Duration) error
	GetOrSet(key string, dest interface{}, ttl time.Duration, getter func() (interface{}, error)) error
}

Interface 缓存封装

func New

func New(args ...interface{}) Interface

func WithGuard

func WithGuard(cache Interface) Interface

func WithPrefix

func WithPrefix(prefix string, cache Interface) Interface

type Item

type Item struct {
	Value     []byte    `json:"v"`
	ExpiredAt time.Time `json:"e"`
}

Item 缓存过期包装

func NewItem

func NewItem(val []byte, ttl time.Duration) *Item

func (*Item) GetValue

func (item *Item) GetValue() ([]byte, bool)

func (*Item) IsExpired

func (item *Item) IsExpired() bool

Jump to

Keyboard shortcuts

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