cache

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// 从缓存中获取数据
	Get(key string, value any) error

	// 将数据存入缓存
	Set(key string, value any, expir time.Duration) error

	// 从缓存中删除数据
	Delete(key string) error
}

func New

func New(config *Config) Cache

type Client

type Client struct {
	Cache Cache
}

func NewClient

func NewClient(cache Cache) *Client

func (*Client) Get

func (c *Client) Get(uuid string, key string, value any, clear bool) error

func (*Client) Set

func (c *Client) Set(key string, v any, expir time.Duration) (string, error)

type Config

type Config struct {
	Use   string
	File  *FileConfig
	Redis *RedisConfig
}

type File

type File struct {
	Client *diskcache.Cache
	Path   string
}

func (*File) Clean

func (f *File) Clean() error

清理过期文件缓存

func (*File) Delete

func (f *File) Delete(key string) error

func (*File) Get

func (f *File) Get(key string, value any) error

func (*File) Set

func (f *File) Set(key string, value any, expir time.Duration) error

type FileConfig

type FileConfig struct {
	Path string
}

type Redis

type Redis struct {
	Context context.Context
	Client  *redis.Client
}

func (*Redis) Delete

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

func (*Redis) Get

func (r *Redis) Get(key string, value any) error

func (*Redis) Set

func (r *Redis) Set(key string, value any, expir time.Duration) error

type RedisConfig

type RedisConfig struct {
	Addr     string
	Password string
}

type Value

type Value struct {
	Expir   time.Time
	IsExpir bool // 是否会过期,true会过期,false不会过期
	Value   any
}

Jump to

Keyboard shortcuts

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