Documentation
¶
Index ¶
- Variables
- func Del(ctx context.Context, c runtimecontract.Container, key string) error
- func Get(ctx context.Context, c runtimecontract.Container, key string) (string, error)
- func GetService(c runtimecontract.Container) (datacontract.Cache, error)
- func GetServiceOrPanic(c runtimecontract.Container) datacontract.Cache
- func MGet(ctx context.Context, c runtimecontract.Container, keys ...string) (map[string]string, error)
- func Remember(ctx context.Context, c runtimecontract.Container, key string, ...) (string, error)
- func Set(ctx context.Context, c runtimecontract.Container, key, value string, ...) error
- type Cache
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCacheMiss = datacontract.ErrCacheMiss
ErrCacheMiss indicates that the cache key does not exist. ErrCacheMiss 表示缓存未命中。
Functions ¶
func GetService ¶
func GetService(c runtimecontract.Container) (datacontract.Cache, error)
GetService returns the unified cache service from the container. GetService 从容器获取统一缓存服务。
func GetServiceOrPanic ¶
func GetServiceOrPanic(c runtimecontract.Container) datacontract.Cache
GetServiceOrPanic returns the unified cache service from the container and panics on failure. GetServiceOrPanic 从容器获取统一缓存服务,失败 panic。
func MGet ¶
func MGet(ctx context.Context, c runtimecontract.Container, keys ...string) (map[string]string, error)
MGet reads multiple cache keys in one call. MGet 批量读取缓存。
func Remember ¶
func Remember(ctx context.Context, c runtimecontract.Container, key string, ttl time.Duration, fn func(context.Context) (string, error)) (string, error)
Remember reads a cache value and falls back to the callback on cache miss. Remember 读取缓存,未命中时回源计算并回填。
Example:
value, err := cache.Remember(ctx, c, "user:42", time.Minute, func(ctx context.Context) (string, error) {
return loadUserJSON(ctx, 42)
})
Types ¶
type Cache ¶
type Cache = datacontract.Cache
Cache is the top-level alias of the unified cache contract. Cache 是统一缓存契约的顶层别名。
Click to show internal directories.
Click to hide internal directories.