cache

package
v0.33.19 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: AGPL-3.0, AGPL-3.0-only Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryCache

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 保存在内存里。

过期的缓存不会从内存中自动回收,不能用来缓存值空间非常大的数据如条目或用户, 用于缓存用户组权限这样的值空间比较小的数据。

func (*MemoryCache[K, T]) Get

func (c *MemoryCache[K, T]) Get(_ context.Context, key K) (T, bool)

func (*MemoryCache[K, T]) Set

func (c *MemoryCache[K, T]) Set(_ context.Context, key K, value T, ttl time.Duration)

type RedisCache

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
}

RedisCache

var s model.Subject
c.Get(ctx, key, &s)
c.Set(ctx, key, s, time.Minute)

func NewNoop

func NewNoop() RedisCache

func NewRedisCache

func NewRedisCache(cli *redis.Client) RedisCache

NewRedisCache create a redis backed cache.

Jump to

Keyboard shortcuts

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