caching

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MEMORY_CACHE_TYPE = "Memory"
	REDIS_CACHE_TYPE  = "Redis"
)

Variables

View Source
var (
	Err_KEY_NOT_FOUND = fmt.Errorf("key not found")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(key string) (interface{}, error)
	Set(key string, value interface{}) error
	SetWithExpiration(key string, value interface{}, expiration time.Duration) error
	GetCtx(ctx context.Context, key string) (interface{}, error)
	SetCtx(ctx context.Context, key string, value interface{}) error
	SetWithExpirationCtx(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	Delete(key string) error
	DeleteCtx(ctx context.Context, key string) error
	Keys(pattern string) ([]string, error)
	KeysCtx(ctx context.Context, pattern string) ([]string, error)
	WithLogger(l *zap.Logger) Cache
	WithTracer(t *tracer.AppInsightsCore) Cache
	WithName(name string) Cache
}

func InitMemoryCache

func InitMemoryCache(
	expiration time.Duration,
	cleanupInterval time.Duration,
) Cache

InitMemoryCache initializes cache with in-memory type params:

  • expiration: expiration time
  • cleanupInterval: cleanup interval

returns:

  • Cache: cache instance

func InitRedisCache

func InitRedisCache(
	url string,
) (Cache, error)

InitRedisCache initializes cache with redis type params:

  • url: redis url

returns:

  • Cache: cache instance
  • error: error if any

Jump to

Keyboard shortcuts

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