cache

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 5 Imported by: 0

README

cache

该目录只是对外公开的便捷转发层。

  • 面向业务代码提供 gorp/cache 入口
  • 真实实现仍在 framework/*
  • 不在这里承载独立缓存实现或新语义

Documentation

Index

Constants

This section is empty.

Variables

ErrCacheMiss indicates that the cache key does not exist. ErrCacheMiss 表示缓存未命中。

Functions

func Del

Del deletes a cache key. Del 删除缓存。

func Get

Get reads a cache value by key. Get 读取缓存。

func GetService

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)
})

func Set

func Set(ctx context.Context, c runtimecontract.Container, key, value string, ttl time.Duration) error

Set writes a cache value with ttl. Set 写入缓存。

Types

type Cache

type Cache = datacontract.Cache

Cache is the top-level alias of the unified cache contract. Cache 是统一缓存契约的顶层别名。

Jump to

Keyboard shortcuts

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