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)
Click to show internal directories.
Click to hide internal directories.