cache

package
v3.0.0-...-3edb00a Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: GPL-3.0 Imports: 11 Imported by: 9

Documentation

Index

Constants

View Source
const DefaultCacheFile = "cache_persist.bin"

Variables

This section is empty.

Functions

func Deletes

func Deletes(keys []string, prefix string) error

Deletes 删除值

func Get

func Get(key string) (interface{}, bool)

Get 获取缓存值

func GetSettings

func GetSettings(keys []string, prefix string) (map[string]string, []string)

GetSettings 根据名称批量获取设置项缓存

func Init

func Init()

Init 初始化缓存

func InitSlaveOverwrites

func InitSlaveOverwrites()

func Restore

func Restore(persistFile string)

Restore restores cache from given disk file

func Set

func Set(key string, value interface{}, ttl int) error

Set 设置缓存值

func SetSettings

func SetSettings(values map[string]string, prefix string) error

SetSettings 批量设置站点设置缓存

Types

type Driver

type Driver interface {
	// 设置值,ttl为过期时间,单位为秒
	Set(key string, value interface{}, ttl int) error

	// 取值,并返回是否成功
	Get(key string) (interface{}, bool)

	// 批量取值,返回成功取值的map即不存在的值
	Gets(keys []string, prefix string) (map[string]interface{}, []string)

	// 批量设置值,所有的key都会加上prefix前缀
	Sets(values map[string]interface{}, prefix string) error

	// 删除值
	Delete(keys []string, prefix string) error

	// Save in-memory cache to disk
	Persist(path string) error

	// Restore cache from disk
	Restore(path string) error
}

Driver 键值缓存存储容器

var Store Driver = NewMemoStore()

Store 缓存存储器

type MemoStore

type MemoStore struct {
	Store *sync.Map
}

MemoStore 内存存储驱动

func NewMemoStore

func NewMemoStore() *MemoStore

NewMemoStore 新建内存存储

func (*MemoStore) Delete

func (store *MemoStore) Delete(keys []string, prefix string) error

Delete 批量删除值

func (*MemoStore) GarbageCollect

func (store *MemoStore) GarbageCollect()

GarbageCollect 回收已过期的缓存

func (*MemoStore) Get

func (store *MemoStore) Get(key string) (interface{}, bool)

Get 取值

func (*MemoStore) Gets

func (store *MemoStore) Gets(keys []string, prefix string) (map[string]interface{}, []string)

Gets 批量取值

func (*MemoStore) Persist

func (store *MemoStore) Persist(path string) error

Persist write memory store into cache

func (*MemoStore) Restore

func (store *MemoStore) Restore(path string) error

Restore memory cache from disk file

func (*MemoStore) Set

func (store *MemoStore) Set(key string, value interface{}, ttl int) error

Set 存储值

func (*MemoStore) Sets

func (store *MemoStore) Sets(values map[string]interface{}, prefix string) error

Sets 批量设置值

type RedisStore

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

RedisStore redis存储驱动

func NewRedisStore

func NewRedisStore(size int, network, address, user, password, database string) *RedisStore

NewRedisStore 创建新的redis存储

func (*RedisStore) Delete

func (store *RedisStore) Delete(keys []string, prefix string) error

Delete 批量删除给定的键

func (*RedisStore) DeleteAll

func (store *RedisStore) DeleteAll() error

DeleteAll 批量所有键

func (*RedisStore) Get

func (store *RedisStore) Get(key string) (interface{}, bool)

Get 取值

func (*RedisStore) Gets

func (store *RedisStore) Gets(keys []string, prefix string) (map[string]interface{}, []string)

Gets 批量取值

func (*RedisStore) Persist

func (store *RedisStore) Persist(path string) error

Persist Dummy implementation

func (*RedisStore) Restore

func (store *RedisStore) Restore(path string) error

Restore dummy implementation

func (*RedisStore) Set

func (store *RedisStore) Set(key string, value interface{}, ttl int) error

Set 存储值

func (*RedisStore) Sets

func (store *RedisStore) Sets(values map[string]interface{}, prefix string) error

Sets 批量设置值

Jump to

Keyboard shortcuts

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