cache

package
v4.80.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: MIT Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bypass added in v4.59.0

func Bypass(ctx context.Context) context.Context

func IsBypassed added in v4.59.0

func IsBypassed(ctx context.Context) bool

Types

type Cache added in v4.64.0

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

func New

func New[K comparable, V any](client RedisClient, toKey keyer[K], onMiss fetch[K, V], tracerProvider trace.TracerProvider) *Cache[K, V]

func (*Cache[K, V]) EvictOnSuccess added in v4.64.0

func (c *Cache[K, V]) EvictOnSuccess(ctx context.Context, id K, err error) error

func (*Cache[K, V]) Get added in v4.64.0

func (c *Cache[K, V]) Get(ctx context.Context, id K) (V, error)

func (*Cache[K, V]) List added in v4.64.0

func (c *Cache[K, V]) List(ctx context.Context, onFetchErr FetchErrHandler[K], ids ...K) (outputs []V, err error)

func (*Cache[K, V]) Store added in v4.64.0

func (c *Cache[K, V]) Store(ctx context.Context, id K, value V) error

func (*Cache[K, V]) WithClientSideCaching added in v4.66.0

func (c *Cache[K, V]) WithClientSideCaching(ctx context.Context, channel string, size int) *Cache[K, V]

func (*Cache[K, V]) WithExtendOnHit added in v4.64.0

func (c *Cache[K, V]) WithExtendOnHit(ctx context.Context, interval time.Duration, maxSize int) *Cache[K, V]

func (*Cache[K, V]) WithMaxConcurrency added in v4.64.0

func (c *Cache[K, V]) WithMaxConcurrency(concurrency int) *Cache[K, V]

func (*Cache[K, V]) WithMissMany added in v4.64.0

func (c *Cache[K, V]) WithMissMany(cb fetchMany[K, V]) *Cache[K, V]

func (*Cache[K, V]) WithRead added in v4.64.0

func (c *Cache[K, V]) WithRead(client RedisClient) *Cache[K, V]

func (*Cache[K, V]) WithSerializer added in v4.64.0

func (c *Cache[K, V]) WithSerializer(serializer Serializer[V]) *Cache[K, V]

func (*Cache[K, V]) WithTTL added in v4.64.0

func (c *Cache[K, V]) WithTTL(ttl time.Duration) *Cache[K, V]

type FetchErrHandler added in v4.70.3

type FetchErrHandler[K comparable] func(context.Context, K, error) error

type IndexedID added in v4.66.2

type IndexedID[K comparable] struct {
	// contains filtered or unexported fields
}

type IndexedIDs added in v4.66.2

type IndexedIDs[K comparable] []IndexedID[K]

func (IndexedIDs[K]) IDs added in v4.66.2

func (ii IndexedIDs[K]) IDs() []K

type JSONSerializer added in v4.62.0

type JSONSerializer[V any] struct{}

func (JSONSerializer[V]) Decode added in v4.62.0

func (JSONSerializer[V]) Decode(payload []byte) (V, error)

func (JSONSerializer[V]) Encode added in v4.62.0

func (JSONSerializer[V]) Encode(payload V) ([]byte, error)

type RedisClient added in v4.28.0

type RedisClient interface {
	Enabled() bool
	Load(ctx context.Context, key string) ([]byte, error)
	LoadMany(ctx context.Context, keys ...string) ([]string, error)
	Store(ctx context.Context, key string, value any, ttl time.Duration) error
	StoreMany(ctx context.Context, values map[string]any, ttl time.Duration) error
	Delete(ctx context.Context, keys ...string) error
	Expire(ctx context.Context, ttl time.Duration, keys ...string) error
	Pipeline() redis.Pipeliner

	PublishJSON(ctx context.Context, channel string, value any) error
	Subscribe(ctx context.Context, channel string) (<-chan *redis.Message, func(context.Context))
}

type Serializer added in v4.62.0

type Serializer[V any] interface {
	Encode(V) ([]byte, error)
	Decode([]byte) (V, error)
}

type StringSerializer added in v4.62.0

type StringSerializer struct{}

func (StringSerializer) Decode added in v4.62.0

func (StringSerializer) Decode(payload []byte) (string, error)

func (StringSerializer) Encode added in v4.62.0

func (StringSerializer) Encode(payload string) ([]byte, error)

type TTLExtender added in v4.68.1

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

func NewExtender added in v4.68.1

func NewExtender(ttl, interval time.Duration, maxSize int, redis RedisClient) *TTLExtender

func (*TTLExtender) Extend added in v4.68.1

func (te *TTLExtender) Extend(ctx context.Context, keys ...string) error

func (*TTLExtender) Start added in v4.68.1

func (te *TTLExtender) Start(ctx context.Context)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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