cache

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

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 interface{}, args ...interface{}) (T, error)

func DecodeKey

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

func StatStr

func StatStr(stat Stat) string

Types

type Cache

type Cache interface {
	CacheKey(fnname string, fn interface{}, args ...interface{}) (string, error)
	Get(key string) (string, bool, error)
	Set(key string, value string, ttl time.Duration) error
	Invalidate(key string) error
	IncHit()
	IncMiss()
	GetStat() Stat
	LaunchRefresh(fn func())
}

func NewCache

func NewCache(ctx context.Context, wg *sync.WaitGroup, config interface{}) 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 interface{}, args ...interface{}) (string, error)

func (CacheBase) EncodeKey

func (cb CacheBase) EncodeKey(key string) string

func (CacheBase) GetStat

func (cb CacheBase) GetStat() Stat

func (*CacheBase) IncHit

func (cb *CacheBase) IncHit()

func (*CacheBase) IncMiss

func (cb *CacheBase) IncMiss()

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) Invalidate

func (imc InMemoryCache) Invalidate(key string) 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 NoCache

type NoCache struct {
}

func NewNoCache

func NewNoCache() *NoCache

func (NoCache) CacheKey

func (nc NoCache) CacheKey(fnname string, fn interface{}, args ...interface{}) (string, error)

func (NoCache) Get

func (nc NoCache) Get(key string) (string, bool, error)

func (NoCache) GetStat

func (nc NoCache) GetStat() Stat

func (NoCache) IncHit

func (nc NoCache) IncHit()

func (NoCache) IncMiss

func (nc NoCache) IncMiss()

func (NoCache) Invalidate

func (nc NoCache) Invalidate(key string) error

func (NoCache) LaunchRefresh

func (nc NoCache) LaunchRefresh(func())

func (NoCache) Set

func (nc NoCache) Set(key string, value string, ttl time.Duration) error

type Stat

type Stat struct {
	Hit  int64
	Miss 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) Invalidate

func (vc *ValkeyCache) Invalidate(key string) 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