cache

package
v1.60.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Code generated by go generate; DO NOT EDIT.

Index

Constants

View Source
const DefaultKeyHash = KEY_HASH_BASE64

Variables

This section is empty.

Functions

func CallCached

func CallCached[T any](c Cache, ttl time.Duration, fnname string, fn any, args ...any) (T, error)

func DecodeKey

func DecodeKey(key string, keyHash KeyHashType) (string, error)

func StatStr

func StatStr(stat Stat) string

func WrapContext1 added in v1.60.1

func WrapContext1[A1 any, R any](
	ctx context.Context,
	f func(context.Context, A1) (R, error),
) func(A1) (R, error)

func WrapContext2 added in v1.60.1

func WrapContext2[A1 any, A2 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2) (R, error),
) func(A1, A2) (R, error)

func WrapContext3 added in v1.60.1

func WrapContext3[A1 any, A2 any, A3 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2, A3) (R, error),
) func(A1, A2, A3) (R, error)

func WrapContext4 added in v1.60.1

func WrapContext4[A1 any, A2 any, A3 any, A4 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2, A3, A4) (R, error),
) func(A1, A2, A3, A4) (R, error)

func WrapContext5 added in v1.60.1

func WrapContext5[A1 any, A2 any, A3 any, A4 any, A5 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2, A3, A4, A5) (R, error),
) func(A1, A2, A3, A4, A5) (R, error)

func WrapContext6 added in v1.60.1

func WrapContext6[A1 any, A2 any, A3 any, A4 any, A5 any, A6 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2, A3, A4, A5, A6) (R, error),
) func(A1, A2, A3, A4, A5, A6) (R, error)

func WrapContext7 added in v1.60.1

func WrapContext7[A1 any, A2 any, A3 any, A4 any, A5 any, A6 any, A7 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2, A3, A4, A5, A6, A7) (R, error),
) func(A1, A2, A3, A4, A5, A6, A7) (R, error)

func WrapContext8 added in v1.60.1

func WrapContext8[A1 any, A2 any, A3 any, A4 any, A5 any, A6 any, A7 any, A8 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2, A3, A4, A5, A6, A7, A8) (R, error),
) func(A1, A2, A3, A4, A5, A6, A7, A8) (R, error)

func WrapContext9 added in v1.60.1

func WrapContext9[A1 any, A2 any, A3 any, A4 any, A5 any, A6 any, A7 any, A8 any, A9 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2, A3, A4, A5, A6, A7, A8, A9) (R, error),
) func(A1, A2, A3, A4, A5, A6, A7, A8, A9) (R, error)

func WrapContext10 added in v1.60.1

func WrapContext10[A1 any, A2 any, A3 any, A4 any, A5 any, A6 any, A7 any, A8 any, A9 any, A10 any, R any](
	ctx context.Context,
	f func(context.Context, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) (R, error),
) func(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) (R, error)

Types

type Cache

type Cache interface {
	CacheKey(fnname string, fn any, args ...any) (string, error)
	Get(key string) (string, bool, error)
	GetAllKeys() ([]string, error)
	Set(key string, value string, ttl time.Duration) error
	Invalidate(key string) error
	InvalidateByMatch(keyMatcher func(decodedKey string) bool) error
	IncHit()
	IncMiss()
	IncShared()
	GetStat() Stat
	LaunchRefresh(fn func())
	GetSingleflightWrapper() SingleflightWrapper
	GetKeyHashType() KeyHashType
}

func NewCache

func NewCache(ctx context.Context, wg *sync.WaitGroup, config any) Cache

type CacheBase

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

func NewCacheBase

func NewCacheBase(ctx context.Context, wg *sync.WaitGroup, config CacheConfig) *CacheBase

func (*CacheBase) CacheKey

func (cb *CacheBase) CacheKey(fnname string, fn any, args ...any) (string, error)

func (*CacheBase) EncodeKey

func (cb *CacheBase) EncodeKey(key string) string

func (*CacheBase) GetSingleflightWrapper added in v1.55.0

func (cb *CacheBase) GetSingleflightWrapper() SingleflightWrapper

func (*CacheBase) GetStat

func (cb *CacheBase) GetStat() Stat

func (*CacheBase) IncHit

func (cb *CacheBase) IncHit()

func (*CacheBase) IncMiss

func (cb *CacheBase) IncMiss()

func (*CacheBase) IncShared added in v1.55.0

func (cb *CacheBase) IncShared()

func (*CacheBase) LaunchRefresh

func (cb *CacheBase) LaunchRefresh(fn func())

type CacheConfig

type CacheConfig struct {
	KeyHash                  KeyHashType
	MonitorInterval          time.Duration
	MaxDbConcurrentRefreshes int
	ThrottleInterval         time.Duration
	ThrottlePerInterval      int
}

type InMemoryCache

type InMemoryCache struct {
	*CacheBase
	// contains filtered or unexported fields
}

func NewInMemoryCache

func NewInMemoryCache(
	ctx context.Context,
	wg *sync.WaitGroup,
	config InMemoryCacheConfig,
) *InMemoryCache

func (*InMemoryCache) Get

func (imc *InMemoryCache) Get(key string) (string, bool, error)

func (*InMemoryCache) GetAllKeys added in v1.60.1

func (imc *InMemoryCache) GetAllKeys() ([]string, error)

func (*InMemoryCache) GetKeyHashType added in v1.60.1

func (imc *InMemoryCache) GetKeyHashType() KeyHashType

func (*InMemoryCache) Invalidate

func (imc *InMemoryCache) Invalidate(key string) error

func (*InMemoryCache) InvalidateByMatch added in v1.60.1

func (imc *InMemoryCache) InvalidateByMatch(keyMatcher func(decodedKey string) bool) error

func (*InMemoryCache) Set

func (imc *InMemoryCache) Set(key string, value string, ttl time.Duration) error

type InMemoryCacheConfig

type InMemoryCacheConfig struct {
	CacheConfig
	CleanupInterval time.Duration
}

type KeyHashType

type KeyHashType int
const (
	KEY_HASH_BASE64 KeyHashType = iota
	KEY_HASH_SHA256
	KEY_HASH_SHA512
	KEY_HASH_HEX
	KEY_HASH_NONE
)

func ParseKeyHashType

func ParseKeyHashType(s string) KeyHashType

func (KeyHashType) String

func (k KeyHashType) String() string

type SingleflightWrapper added in v1.55.0

type SingleflightWrapper interface {
	Do(string, func() (any, error)) (any, error, bool)
}

type Stat

type Stat struct {
	Hit    int64
	Miss   int64
	Shared int64
}

type ValkeyCache

type ValkeyCache struct {
	*CacheBase
	// contains filtered or unexported fields
}

func NewValkeyCache

func NewValkeyCache(
	ctx context.Context,
	wg *sync.WaitGroup,
	config ValkeyCacheConfig,
) *ValkeyCache

func (*ValkeyCache) Get

func (vc *ValkeyCache) Get(key string) (string, bool, error)

func (*ValkeyCache) GetAllKeys added in v1.60.1

func (vc *ValkeyCache) GetAllKeys() ([]string, error)

func (*ValkeyCache) GetKeyHashType added in v1.60.1

func (vc *ValkeyCache) GetKeyHashType() KeyHashType

func (*ValkeyCache) Invalidate

func (vc *ValkeyCache) Invalidate(key string) error

func (*ValkeyCache) InvalidateByMatch added in v1.60.1

func (vc *ValkeyCache) InvalidateByMatch(keyMatcher func(decodedKey string) bool) error

func (*ValkeyCache) Set

func (vc *ValkeyCache) Set(key string, value string, ttl time.Duration) error

ttl = 0 <- infinite

type ValkeyCacheConfig

type ValkeyCacheConfig struct {
	CacheConfig
	Url        string
	Username   string
	Password   string
	ClientName string
	Db         int
}

Jump to

Keyboard shortcuts

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