cache

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRefHMapCycle       = errors.New("cache: redis ref hmap cycle")
	ErrRefHMapMaxDepth    = errors.New("cache: redis ref hmap max depth exceeded")
	ErrRefHMapUnsupported = errors.New("cache: redis ref hmap unsupported field")
)
View Source
var (
	ErrKeyFuncNil = errors.New("cache: key func is nil")
	ErrInvalidKey = errors.New("cache: invalid key")
)

Functions

func PatchStructPath

func PatchStructPath(target any, path string, value any) error

Types

type GroupedLocalStore added in v1.0.1

type GroupedLocalStore[G comparable, K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewGroupedLocalStore added in v1.0.1

func NewGroupedLocalStore[G comparable, K comparable, V any](groupOf func(K) G, cfg StoreConfig[K, V]) *GroupedLocalStore[G, K, V]

func (*GroupedLocalStore[G, K, V]) Delete added in v1.0.1

func (s *GroupedLocalStore[G, K, V]) Delete(_ context.Context, key K) error

func (*GroupedLocalStore[G, K, V]) DeleteGroup added in v1.0.1

func (s *GroupedLocalStore[G, K, V]) DeleteGroup(_ context.Context, groupKey G) error

func (*GroupedLocalStore[G, K, V]) Get added in v1.0.1

func (s *GroupedLocalStore[G, K, V]) Get(_ context.Context, key K) (V, bool, error)

func (*GroupedLocalStore[G, K, V]) Set added in v1.0.1

func (s *GroupedLocalStore[G, K, V]) Set(_ context.Context, value V) error

type KeyFunc added in v1.0.1

type KeyFunc[K comparable, V any] func(V) K

type LayeredStore added in v1.0.1

type LayeredStore[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewLayeredStore added in v1.0.1

func NewLayeredStore[K comparable, V any](local Store[K, V], remote Store[K, V], ttl time.Duration, cfg StoreConfig[K, V]) *LayeredStore[K, V]

func (*LayeredStore[K, V]) Delete added in v1.0.1

func (s *LayeredStore[K, V]) Delete(ctx context.Context, key K) error

func (*LayeredStore[K, V]) Get added in v1.0.1

func (s *LayeredStore[K, V]) Get(ctx context.Context, key K) (V, bool, error)

func (*LayeredStore[K, V]) Set added in v1.0.1

func (s *LayeredStore[K, V]) Set(ctx context.Context, value V) error

type LocalStore added in v1.0.1

type LocalStore[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewLocalStore added in v1.0.1

func NewLocalStore[K comparable, V any](cfg StoreConfig[K, V], opts ...LocalStoreOption[K, V]) *LocalStore[K, V]

func (*LocalStore[K, V]) Delete added in v1.0.1

func (s *LocalStore[K, V]) Delete(_ context.Context, key K) error

func (*LocalStore[K, V]) Get added in v1.0.1

func (s *LocalStore[K, V]) Get(_ context.Context, key K) (V, bool, error)

func (*LocalStore[K, V]) Set added in v1.0.1

func (s *LocalStore[K, V]) Set(_ context.Context, value V) error

type LocalStoreOption added in v1.0.1

type LocalStoreOption[K comparable, V any] func(*LocalStore[K, V])

func WithLocalMaxEntries added in v1.0.1

func WithLocalMaxEntries[K comparable, V any](maxEntries int) LocalStoreOption[K, V]

type RedisHashKey

type RedisHashKey struct {
	Key   string
	Field string
}

type RedisHashKeyFunc

type RedisHashKeyFunc[K comparable] func(K) RedisHashKey

type RedisJSONHashStore

type RedisJSONHashStore[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewRedisJSONHashStore

func NewRedisJSONHashStore[K comparable, V any](redis fredis.IRedis, ttl time.Duration, key RedisHashKeyFunc[K], cfg StoreConfig[K, V]) *RedisJSONHashStore[K, V]

func (*RedisJSONHashStore[K, V]) Delete

func (s *RedisJSONHashStore[K, V]) Delete(ctx context.Context, key K) error

func (*RedisJSONHashStore[K, V]) Get

func (s *RedisJSONHashStore[K, V]) Get(ctx context.Context, key K) (V, bool, error)

func (*RedisJSONHashStore[K, V]) Set

func (s *RedisJSONHashStore[K, V]) Set(ctx context.Context, value V) error

type RedisJSONStore

type RedisJSONStore[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewRedisJSONStore

func NewRedisJSONStore[K comparable, V any](redis fredis.IRedis, ttl time.Duration, key RedisKeyFunc[K], cfg StoreConfig[K, V]) *RedisJSONStore[K, V]

func (*RedisJSONStore[K, V]) Delete

func (s *RedisJSONStore[K, V]) Delete(ctx context.Context, key K) error

func (*RedisJSONStore[K, V]) Get

func (s *RedisJSONStore[K, V]) Get(ctx context.Context, key K) (V, bool, error)

func (*RedisJSONStore[K, V]) Set

func (s *RedisJSONStore[K, V]) Set(ctx context.Context, value V) error

type RedisKeyFunc

type RedisKeyFunc[K comparable] func(K) string

type RedisRawJSONStore

type RedisRawJSONStore[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewRedisRawJSONStore

func NewRedisRawJSONStore[K comparable, V any](redis fredis.IRedis, ttl time.Duration, key RedisKeyFunc[K], cfg StoreConfig[K, V]) *RedisRawJSONStore[K, V]

func (*RedisRawJSONStore[K, V]) Delete

func (s *RedisRawJSONStore[K, V]) Delete(ctx context.Context, key K) error

func (*RedisRawJSONStore[K, V]) Get

func (s *RedisRawJSONStore[K, V]) Get(ctx context.Context, key K) (V, bool, error)

func (*RedisRawJSONStore[K, V]) Set

func (s *RedisRawJSONStore[K, V]) Set(ctx context.Context, value V) error

type RedisRawSortedSetStore

type RedisRawSortedSetStore[M ~int64 | ~int | ~string] struct {
	// contains filtered or unexported fields
}

func NewRedisRawSortedSetStore

func NewRedisRawSortedSetStore[M ~int64 | ~int | ~string](redis fredis.IRedis, key string, ttl time.Duration) *RedisRawSortedSetStore[M]

func (*RedisRawSortedSetStore[M]) Delete

func (s *RedisRawSortedSetStore[M]) Delete(ctx context.Context, member M) error

func (*RedisRawSortedSetStore[M]) Score

func (s *RedisRawSortedSetStore[M]) Score(ctx context.Context, member M) (float64, bool, error)

func (*RedisRawSortedSetStore[M]) SetScore

func (s *RedisRawSortedSetStore[M]) SetScore(ctx context.Context, member M, score float64) error

type RedisRefHMapStore

type RedisRefHMapStore[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewRedisRefHMapStore

func NewRedisRefHMapStore[K comparable, V any](redis fredis.IRedis, cfg RefHMapConfig[K, V]) *RedisRefHMapStore[K, V]

func (*RedisRefHMapStore[K, V]) Delete

func (s *RedisRefHMapStore[K, V]) Delete(ctx context.Context, key K) error

func (*RedisRefHMapStore[K, V]) Get

func (s *RedisRefHMapStore[K, V]) Get(ctx context.Context, key K) (V, bool, error)

func (*RedisRefHMapStore[K, V]) Patch

func (s *RedisRefHMapStore[K, V]) Patch(ctx context.Context, key K, path string, value any) error

func (*RedisRefHMapStore[K, V]) Set

func (s *RedisRefHMapStore[K, V]) Set(ctx context.Context, value V) error

type RefHMapConfig

type RefHMapConfig[K comparable, V any] struct {
	Prefix      string
	Name        string
	TTL         time.Duration
	MaxDepth    int
	KeyString   RefHMapKeyStringFunc[K]
	StoreConfig StoreConfig[K, V]
}

type RefHMapKeyStringFunc

type RefHMapKeyStringFunc[K comparable] func(K) string

type RefHMapPatcher

type RefHMapPatcher[K comparable] interface {
	Patch(ctx context.Context, key K, path string, value any) error
}

type ReplicaConfig

type ReplicaConfig[K comparable, V any] struct {
	Store       Store[K, V]
	Topic       string
	KeyOf       func(V) int64
	VersionOf   func(V) int64
	UpdatedAtOf func(V) int64
	DeleteKeyOf func(replicaKey int64) K
}

type ReplicaSyncer

type ReplicaSyncer[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewReplicaSyncer

func NewReplicaSyncer[K comparable, V any](bus fsync.ISyncBus, cfg ReplicaConfig[K, V]) *ReplicaSyncer[K, V]

func (*ReplicaSyncer[K, V]) Publish

func (s *ReplicaSyncer[K, V]) Publish(ctx context.Context, value V) error

func (*ReplicaSyncer[K, V]) PublishDelete

func (s *ReplicaSyncer[K, V]) PublishDelete(ctx context.Context, replicaKey int64, version int64) error

func (*ReplicaSyncer[K, V]) Start

func (s *ReplicaSyncer[K, V]) Start() error

func (*ReplicaSyncer[K, V]) Stop

func (s *ReplicaSyncer[K, V]) Stop()

type StaleFunc added in v1.0.1

type StaleFunc[V any] func(old V, next V) bool

func VersionStale added in v1.0.1

func VersionStale[V any](versionOf func(V) int64) StaleFunc[V]

type Store added in v1.0.1

type Store[K comparable, V any] interface {
	Get(ctx context.Context, key K) (V, bool, error)
	Set(ctx context.Context, value V) error
	Delete(ctx context.Context, key K) error
}

type StoreConfig added in v1.0.1

type StoreConfig[K comparable, V any] struct {
	KeyOf         KeyFunc[K, V]
	Stale         StaleFunc[V]
	ValidateKey   ValidateKeyFunc[K]
	ValidateValue ValidateValueFunc[V]
}

type ValidateKeyFunc added in v1.0.1

type ValidateKeyFunc[K comparable] func(K) bool

type ValidateValueFunc added in v1.0.1

type ValidateValueFunc[V any] func(V) error

Jump to

Keyboard shortcuts

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