cache

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMemCache

func NewMemCache()

func NewRedisCache

func NewRedisCache(host string, password string, db int) error

Types

type CacheMem

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

func (*CacheMem) Close

func (s *CacheMem) Close() error

func (*CacheMem) Get

func (s *CacheMem) Get(key string) (string, error)

读取缓存

func (*CacheMem) GetBytes

func (s *CacheMem) GetBytes(key string) ([]byte, error)

func (*CacheMem) Ping

func (s *CacheMem) Ping() (string, error)

func (*CacheMem) Set

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

设置缓存

type CacheRedis

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

func (*CacheRedis) Close

func (c *CacheRedis) Close() error

func (*CacheRedis) Get

func (c *CacheRedis) Get(key string) (string, error)

读取缓存

func (*CacheRedis) GetBytes

func (c *CacheRedis) GetBytes(key string) ([]byte, error)

func (*CacheRedis) Ping

func (c *CacheRedis) Ping() (string, error)

func (*CacheRedis) Set

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

设置缓存

type ICache

type ICache interface {
	Set(key string, val interface{}, expiration time.Duration) error
	Get(key string) (string, error)
	GetBytes(key string) ([]byte, error) // 获取缓存的 bytes
	// GetKey() string                      // 生成key值
	Ping() (string, error)
	Close() error // 关闭连接
}

抽象 cache 类

func GetCache

func GetCache() ICache

全局唯一

Jump to

Keyboard shortcuts

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