cache

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultExpireTime
	DefaultExpireTime = 60 * time.Second
	// PrefixCacheKey cache key
	PrefixCacheKey = "nocalhost"
)

Variables

This section is empty.

Functions

func BuildCacheKey

func BuildCacheKey(keyPrefix string, key string) (cacheKey string, err error)

BuildCacheKey

func Decr

func Decr(key string, step int64) (int64, error)

Decr

func Del

func Del(keys ...string) error

Del

func Get

func Get(key string, val interface{}) error

Get

func GzipDecode

func GzipDecode(in []byte) ([]byte, error)

GzipDecode

func GzipEncode

func GzipEncode(in []byte) ([]byte, error)

GzipEncode

func Incr

func Incr(key string, step int64) (int64, error)

Incr

func Marshal

func Marshal(e Encoding, v interface{}) (data []byte, err error)

Marshal encode data

func MultiGet

func MultiGet(keys []string, valueMap interface{}) error

MultiGet

func MultiSet

func MultiSet(valMap map[string]interface{}, expiration time.Duration) error

MultiSet

func Set

func Set(key string, val interface{}, expiration time.Duration) error

Set

func Unmarshal

func Unmarshal(e Encoding, data []byte, v interface{}) (err error)

Unmarshal decode data

Types

type Driver

type Driver interface {
	Set(key string, val interface{}, expiration time.Duration) error
	Get(key string, val interface{}) error
	MultiSet(valMap map[string]interface{}, expiration time.Duration) error
	MultiGet(keys []string, valueMap interface{}) error
	Del(keys ...string) error
	Incr(key string, step int64) (int64, error)
	Decr(key string, step int64) (int64, error)
}

Driver

var Client Driver

func NewMemoryCache

func NewMemoryCache(keyPrefix string, encoding Encoding) Driver

NewMemoryCache

func NewRedisCache

func NewRedisCache(client *redis.Client, keyPrefix string, encoding Encoding, newObject func() interface{}) Driver

NewRedisCache

type Encoding

type Encoding interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
}

Encoding

type GobEncoding

type GobEncoding struct{}

GobEncoding gob encode

func (GobEncoding) Marshal

func (g GobEncoding) Marshal(v interface{}) ([]byte, error)

Marshal gob encode

func (GobEncoding) Unmarshal

func (g GobEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal gob encode

type JSONEncoding

type JSONEncoding struct{}

JSONEncoding

func (JSONEncoding) Marshal

func (j JSONEncoding) Marshal(v interface{}) ([]byte, error)

Marshal json encode

func (JSONEncoding) Unmarshal

func (j JSONEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal json decode

type JSONGzipEncoding

type JSONGzipEncoding struct{}

JSONGzipEncoding json and gzip

func (JSONGzipEncoding) Marshal

func (jz JSONGzipEncoding) Marshal(v interface{}) ([]byte, error)

Marshal json encode and gzip

func (JSONGzipEncoding) Unmarshal

func (jz JSONGzipEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal json encode and gzip

type JSONSnappyEncoding

type JSONSnappyEncoding struct{}

JSONSnappyEncoding

func (JSONSnappyEncoding) Marshal

func (s JSONSnappyEncoding) Marshal(v interface{}) (data []byte, err error)

Marshal 序列化

func (JSONSnappyEncoding) Unmarshal

func (s JSONSnappyEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal

type MsgPackEncoding

type MsgPackEncoding struct{}

MsgPackEncoding msgpack

func (MsgPackEncoding) Marshal

func (mp MsgPackEncoding) Marshal(v interface{}) ([]byte, error)

Marshal msgpack encode

func (MsgPackEncoding) Unmarshal

func (mp MsgPackEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal msgpack decode

Jump to

Keyboard shortcuts

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