cache

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheSecond = 1
	CacheMinute = 60
	CacheHour   = 60 * CacheMinute
	CacheDay    = 24 * CacheHour
	CacheWeek   = 7 * CacheDay
)

time for cache unit unit: second

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Init init cache
	Init() error

	// Set value
	// if time != 0 set it
	Set(key any, value CacheModel) error
	// Get value
	Get(key any) (CacheModel, error)
	// Delete value
	Delete(key any) error
	// DeleteMore more del
	// key will become *key*
	DeleteMore(key any) error
	// Check value
	// flush the time
	Check(key any) error
	// ExpireKey expire key time
	ExpireKey(key any, seconds int64) bool
}

Cache manager

func NewCache

func NewCache(params ...any) (cache Cache)

NewCache cache sugar the first param is Cache the second param is confDir

func NewRedis

func NewRedis(redis *Redis) (cache Cache)

NewRedis new your custom redis

type CacheModel

type CacheModel struct {
	// seconds
	Time int64 `json:"time,omitempty"`
	// data
	Data any `json:"data,omitempty"`
}

CacheModel data model

func (CacheModel) Unmarshal

func (c CacheModel) Unmarshal(v any) error

Unmarshal support Struct/Array c.Data to v

type Redis

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

Redis impl cache manager redis cache interface key, interface value

func (*Redis) Check

func (r *Redis) Check(key any) error

func (*Redis) Delete

func (r *Redis) Delete(key any) error

func (*Redis) DeleteMore

func (r *Redis) DeleteMore(key any) error

func (*Redis) ExpireKey

func (r *Redis) ExpireKey(key any, seconds int64) bool

func (*Redis) Get

func (r *Redis) Get(key any) (CacheModel, error)

func (*Redis) Init

func (r *Redis) Init() error

func (*Redis) Set

func (r *Redis) Set(key any, value CacheModel) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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