Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalMany ¶ added in v0.27.6
func MarshalMany[M ~map[K]V, K comparable, V any, F func(t K) string](data M, fn F) map[string]any
func UnmarshalMany ¶ added in v0.27.6
func UnmarshalMany[T any, ID comparable, F func(t T) ID](result GetManyResult, fn F) (map[ID]T, error)
Types ¶
type GetManyResult ¶ added in v0.27.6
type MemoryCache ¶ added in v0.27.4
type MemoryCache[K comparable, T any] struct { // contains filtered or unexported fields }
MemoryCache store data in memory, will be used to cache user group permission rule.
func NewMemoryCache ¶
func NewMemoryCache[K comparable, V any]() *MemoryCache[K, V]
NewMemoryCache 不对缓存的对象进行序列化,直接用 sync.Map 保存在内存里。
过期的缓存不会从内存中自动回收,不能用来缓存值空间非常大的数据如条目或用户, 用于缓存用户组权限这样的值空间比较小的数据。
type RedisCache ¶ added in v0.27.4
type RedisCache interface { Get(ctx context.Context, key string, value any) (bool, error) Set(ctx context.Context, key string, value any, ttl time.Duration) error Del(ctx context.Context, keys ...string) error SetMany(ctx context.Context, data map[string]any, ttl time.Duration) error GetMany(ctx context.Context, keys []string) GetManyResult }
RedisCache
var s model.Subject c.Get(ctx, key, &s) c.Set(ctx, key, s, time.Minute)
SetMany...
err := c.SetMany(ctx, cache.MarshalMany(notCachedSubjects, cachekey.Subject), time.Minute)
GetMany...
result := c.GetMany(ctx, slice.Map(subjectIDs, cachekey.Subject)) var cached map[model.SubjectID]model.Subject cached, err = cache.UnmarshalMany(result, model.Subject.GetID)
func NewNoop ¶ added in v0.27.4
func NewNoop() RedisCache
func NewRedisCache ¶
func NewRedisCache(cli *redis.Client) RedisCache
NewRedisCache create a redis backed cache.
Click to show internal directories.
Click to hide internal directories.