cache

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 10 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, expire 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) Delete

func (c *Client) Delete(id string, key string) error

func (*Client) Get

func (c *Client) Get(id string, key string, value any) error

func (*Client) GetAndDelete

func (c *Client) GetAndDelete(id string, key string, value any) 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
	// contains filtered or unexported fields
}

func NewFile

func NewFile(config *FileConfig) *File

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, expire time.Duration) error

type FileConfig

type FileConfig struct {
	Path string
}

type Redis

type Redis struct {
	Client *redis.Client
}

func NewRedis

func NewRedis(config *RedisConfig) *Redis

func (*Redis) Delete

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

func (*Redis) DeleteWithContext

func (r *Redis) DeleteWithContext(ctx context.Context, key string) error

func (*Redis) Get

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

func (*Redis) GetWithContext

func (r *Redis) GetWithContext(ctx context.Context, key string, value any) error

func (*Redis) Ping

func (r *Redis) Ping(ctx context.Context) error

func (*Redis) Set

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

func (*Redis) SetWithContext

func (r *Redis) SetWithContext(ctx context.Context, key string, value any, expir time.Duration) error

type RedisConfig

type RedisConfig struct {
	Addr     string
	Password string
	DB       int
}

type Value

type Value struct {
	Expire    time.Time
	HasExpire bool
	Value     any
}

Jump to

Keyboard shortcuts

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