Documentation
¶
Index ¶
- func Get[T any](cache Cache, ctx context.Context, key string, ...) (*T, error)
- type Cache
- type Options
- type RedisCache
- func (s *RedisCache) Exist(ctx context.Context, key string) (bool, error)
- func (s *RedisCache) Get(ctx context.Context, key string, value interface{}) (exist bool, err error)
- func (s *RedisCache) Put(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- func (s *RedisCache) Remove(ctx context.Context, key string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
func Get[T any](cache Cache, ctx context.Context, key string, callback func(ctx context.Context) (*T, error), options *Options) (*T, error)
Get gets value from the cache, load from callback function if cache value does not exist. Example:
cache.Get(cacheInstance, ctx, "workspaces:uid", func(ctx context.Context) (*entities.Workspace, error) { return db.Workspace.Get(ctx, workspaceId) }, nil)
Types ¶
type Cache ¶
type Cache interface { Put(ctx context.Context, key string, val interface{}, expiration time.Duration) error Get(ctx context.Context, key string, val interface{}) (exist bool, err error) Remove(ctx context.Context, key string) error Exist(ctx context.Context, key string) (bool, error) }
func NewRedisCache ¶
func NewRedisCache(client *redis.Client) Cache
Click to show internal directories.
Click to hide internal directories.