cache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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

type Options

type Options struct {
	Expiration time.Duration
}

type RedisCache

type RedisCache struct {
	// contains filtered or unexported fields
}

func (*RedisCache) Exist

func (s *RedisCache) Exist(ctx context.Context, key string) (bool, error)

func (*RedisCache) Get

func (s *RedisCache) Get(ctx context.Context, key string, value interface{}) (exist bool, err error)

func (*RedisCache) Put

func (s *RedisCache) Put(ctx context.Context, key string, value interface{}, expiration time.Duration) error

func (*RedisCache) Remove

func (s *RedisCache) Remove(ctx context.Context, key string) error

Jump to

Keyboard shortcuts

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