cacher

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLRUSize                  = 16
	Byte                 MemStorage = 1
	KiloByte                        = 1024 * Byte
	MegaByte                        = 1024 * KiloByte
	DefaultMinMemStorage MemStorage = 32 * MegaByte
	DefaultMaxMemStorage MemStorage = 128 * MegaByte
)

Variables

View Source
var ErrCastError = fmt.Errorf("cast to IPokeBall interface failed")
View Source
var ErrExceedStorage = fmt.Errorf("the new item cannot be fit into the member because of the size limitation")
View Source
var ErrNotInCache = fmt.Errorf("not in cache")

Functions

This section is empty.

Types

type Cacher

type Cacher interface {
	Get(ctx context.Context, key string) (IPokeBall, error)
	Set(ctx context.Context, ball IPokeBall) error
	Contains(ctx context.Context, key string) bool
}

func NewLRUCacher

func NewLRUCacher(size int, evictedCallback func(key interface{}, val interface{})) Cacher

func NewRedisCacher

func NewRedisCacher(cli *redis.Client) Cacher

type IPokeBall

type IPokeBall interface {
	GetKey() string
	GetVal() []byte
	GetTTL() UnixTime

	IsFaded() bool
}

type MemStorage

type MemStorage int64

type PokeBall

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

func NewPokeBall

func NewPokeBall(key string, ttl UnixTime, val []byte) *PokeBall

func (*PokeBall) GetKey

func (p *PokeBall) GetKey() string

func (*PokeBall) GetTTL

func (p *PokeBall) GetTTL() UnixTime

func (*PokeBall) GetVal

func (p *PokeBall) GetVal() []byte

func (*PokeBall) IsFaded

func (p *PokeBall) IsFaded() bool

type UnixTime

type UnixTime int64

Jump to

Keyboard shortcuts

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