xcache

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

* @Date: 2023-07-20 09:46:36 * @LastEditTime: 2023-07-20 09:46:37 * @Description:

* @Date: 2023-07-20 09:46:36 * @LastEditTime: 2023-07-20 09:47:05 * @Description:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromExpiration

func FromExpiration(ctx context.Context) (time.Duration, bool)

FromExpiration @param ctx @date 2022-07-02 08:11:40

func FromKey

func FromKey(ctx context.Context) (string, bool)

FromKey @param ctx @date 2022-07-02 08:11:39

func FromTag

func FromTag(ctx context.Context) (string, bool)

FromTag @param ctx @date 2022-07-02 08:11:37

func NewExpiration

func NewExpiration(ctx context.Context, ttl time.Duration) context.Context

NewExpiration @param ctx @param ttl @date 2022-07-02 08:11:41

func NewKey

func NewKey(ctx context.Context, key string) context.Context

NewKey @param ctx @param key @date 2022-07-02 08:11:44

func NewTag

func NewTag(ctx context.Context, key string) context.Context

NewTag @param ctx @param key @date 2022-07-02 08:11:43

Types

type Cache

type Cache struct {

	// Serializer 序列化
	Serializer Serializer
	// contains filtered or unexported fields
}

func New

func New(conf *Config) *Cache

New @param conf @date 2022-07-02 08:09:52

func (*Cache) Initialize

func (p *Cache) Initialize(tx *gorm.DB) error

Initialize @param tx @date 2022-07-02 08:09:47

func (*Cache) MemberTagKey

func (p *Cache) MemberTagKey(ctx context.Context, tag string, key string) (bool, error)

MemberTagKey 是否缓存数据

func (*Cache) Name

func (p *Cache) Name() string

Name @date 2022-07-02 08:09:48

func (*Cache) Query

func (p *Cache) Query(tx *gorm.DB)

Query @param tx @date 2022-07-02 08:09:38

func (*Cache) QueryCache

func (p *Cache) QueryCache(ctx context.Context, key string, dest any) error

QueryCache 查询缓存数据 @param ctx @param key @param dest

func (*Cache) QueryDB

func (p *Cache) QueryDB(tx *gorm.DB)

QueryDB 查询数据库数据 这里重写Query方法 是不想执行 callbacks.BuildQuerySQL 两遍

func (*Cache) RemoveFromKey

func (p *Cache) RemoveFromKey(ctx context.Context, key string) error

RemoveFromTag 根据key删除缓存数据 @param ctx @param key @date 2022-07-02 08:08:59

func (*Cache) RemoveFromTag

func (p *Cache) RemoveFromTag(ctx context.Context, tag string) error

RemoveFromTag 根据tag删除缓存数据 @param ctx @param tag @date 2022-07-02 08:08:59

func (*Cache) RemoveTagCache

func (p *Cache) RemoveTagCache(ctx context.Context, tag string, key string) error

RemoveTagCache 删除缓存数据

func (*Cache) SaveCache

func (p *Cache) SaveCache(ctx context.Context, key string, dest any, ttl time.Duration) error

SaveCache 写入缓存数据

func (*Cache) SaveTagCache

func (p *Cache) SaveTagCache(ctx context.Context, tag string, key string) error

SaveCache 写入缓存数据

type Config

type Config struct {
	Store Store

	Prefix string

	Serializer Serializer
}

type DefaultJSONSerializer

type DefaultJSONSerializer struct{}

func (*DefaultJSONSerializer) Deserialize

func (d *DefaultJSONSerializer) Deserialize(data []byte, v any) error

Deserialize @param data @param v @date 2022-07-02 08:12:25

func (*DefaultJSONSerializer) Serialize

func (d *DefaultJSONSerializer) Serialize(v any) ([]byte, error)

Serialize @param v @date 2022-07-02 08:12:26

type Serializer

type Serializer interface {
	Serialize(v any) ([]byte, error)

	Deserialize(data []byte, v any) error
}

type Store

type Store interface {
	// Set 写入缓存数据
	Set(ctx context.Context, key string, value any, ttl time.Duration) error

	// Get 获取缓存数据
	Get(ctx context.Context, key string) ([]byte, error)

	// SaveTagKey 将缓存key写入tag
	SaveTagKey(ctx context.Context, tag, key string) error

	// RemoveTagKey 将缓存key从tag中删除
	RemoveTagKey(ctx context.Context, tag, key string) error

	// MemberTagKey 判断key在tag中
	MemberTagKey(ctx context.Context, tag, key string) (bool, error)

	// RemoveFromTag 根据缓存tag删除缓存
	RemoveFromTag(ctx context.Context, tag string) error

	// RemoveFromKey 根据缓存key删除缓存
	RemoveFromKey(ctx context.Context, key string) error
}

Directories

Path Synopsis
store
redis
* @Date: 2023-07-20 09:48:51 * @LastEditTime: 2023-07-20 09:48:52 * @Description:
* @Date: 2023-07-20 09:48:51 * @LastEditTime: 2023-07-20 09:48:52 * @Description:

Jump to

Keyboard shortcuts

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