gwcache

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderNameMemory       = "memory"
	ProviderNameRedis        = "redis"
	ServiceCachePrefix       = "_SC_"
	ServiceCacheKeySetPrefix = "_SC_SET_"
	ServiceCacheLockerPrefix = "_LOCK_"
)

Variables

View Source
var (
	CacheEnabled      = false
	DebugEnabled      = false
	TracingEnabled    = false
	CacheProviderName = "unknown"

	ErrCacheNotInitialized = errors.New("cache: not initialized")
	ErrEmptyCacheKey       = errors.New("cache: cache key is empty")
	ErrLockTimeout         = errors.New("cache: lock timeout")
	ErrNotFound            = errors.New("cache: not found")
	ErrEmptyCachedValue    = errors.New("cache: cached value is empty")
)

Functions

func GetCacheKey

func GetCacheKey(ctx context.Context, serviceName string, funcName string, funcParams proto.Message) *string

GetCacheKey 生成cacheKey serviceName service名称,不同service名称不要相同,否则会造成 cacheKey 冲突,可以将 serviceName 当做某些缓存实现的 namespace 看待 funcName method名称,不同funcName名称不要相同,否则会造成 cacheKey 冲突 funcParams 所有的method参数

Types

type CacheProvider

type CacheProvider interface {
	Initialized() bool
	RetrieveCacheTo(ctx context.Context, cacheKey *string, value proto.Message) error
	SaveCache(ctx context.Context, serviceName string, cacheKey *string, value any, ttlSeconds uint32) error
	RemoveCache(ctx context.Context, cacheKey *string) error
	ClearCache(ctx context.Context, serviceName string) error
}

func GetCacheProvider

func GetCacheProvider() (CacheProvider, error)

func NewMemoryCacheProvider

func NewMemoryCacheProvider(ctx context.Context) (CacheProvider, error)

func NewRedisCacheProvider

func NewRedisCacheProvider(ctx context.Context) (CacheProvider, error)

type Setting

type Setting struct {
	Enabled bool
	Name    string // todo implements custom specified name
	Key     string // todo implements custom specified key
	Adapter string // todo implements memory adapter
	Ttl     uint32
}

func ParseCacheTag

func ParseCacheTag(ctx context.Context, cacheTag string) Setting

Jump to

Keyboard shortcuts

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