Documentation
¶
Index ¶
- Variables
- func DefaultRedisClient() *redis.Client
- func NewEncodedCache[T any](cache cache.CacheInterface[string], transcoder BinaryTranscoder[T], ...) cache.CacheInterface[T]
- func NewTransparentRedisCache[T any](redisClient *redis.Client, transcoder BinaryTranscoder[T], ttl time.Duration) cache.CacheInterface[T]
- func RedisClient(config RedisClientConfig) (*redis.Client, error)
- type BinaryTranscoder
- type Cache
- type CacheInterface
- type CollectionCache
- type CplnCacheEntry
- type CplnRedisStore
- func (c *CplnRedisStore[T]) Clear(ctx context.Context) error
- func (c *CplnRedisStore[T]) Delete(ctx context.Context, key any) error
- func (c *CplnRedisStore[T]) Get(ctx context.Context, key any) (any, error)
- func (c *CplnRedisStore[T]) GetType() string
- func (c *CplnRedisStore[T]) GetWithTTL(ctx context.Context, key any) (any, time.Duration, error)
- func (c *CplnRedisStore[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
- func (c *CplnRedisStore[T]) Set(ctx context.Context, key any, value any, options ...store.Option) error
- type EncodedCache
- func (r *EncodedCache[T]) Clear(ctx context.Context) error
- func (r *EncodedCache[T]) Delete(ctx context.Context, key any) error
- func (r *EncodedCache[T]) Get(ctx context.Context, key any) (T, error)
- func (r *EncodedCache[T]) GetType() string
- func (r *EncodedCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
- func (r *EncodedCache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error
- type JsonCplnCacheEntry
- type JsonTranscoder
- type RedisClientConfig
- type RedisCollectionCache
- func (c *RedisCollectionCache[T]) Clear(ctx context.Context) error
- func (c *RedisCollectionCache[T]) Delete(ctx context.Context, name string) error
- func (c *RedisCollectionCache[T]) DeleteMany(ctx context.Context, names []string) error
- func (c *RedisCollectionCache[T]) Exists(ctx context.Context, name string) (bool, error)
- func (c *RedisCollectionCache[T]) Get(ctx context.Context, name string) (*T, error)
- func (c *RedisCollectionCache[T]) IsValid(ctx context.Context) (bool, error)
- func (c *RedisCollectionCache[T]) ListAll(ctx context.Context) ([]*T, error)
- func (c *RedisCollectionCache[T]) MarkValid(ctx context.Context, ttl time.Duration) error
- func (c *RedisCollectionCache[T]) Set(ctx context.Context, item *T) error
- func (c *RedisCollectionCache[T]) SetMany(ctx context.Context, items []*T) error
- type RedisMode
Constants ¶
This section is empty.
Variables ¶
View Source
var NoHostProvidedErr error = errors.New("no host provided")
View Source
var RedisModeHa = RedisMode("ha")
View Source
var RedisModeStandalone = RedisMode("standalone")
Functions ¶
func DefaultRedisClient ¶
func NewEncodedCache ¶
func NewEncodedCache[T any](cache cache.CacheInterface[string], transcoder BinaryTranscoder[T], ttl time.Duration) cache.CacheInterface[T]
func NewTransparentRedisCache ¶
func NewTransparentRedisCache[T any](redisClient *redis.Client, transcoder BinaryTranscoder[T], ttl time.Duration) cache.CacheInterface[T]
func RedisClient ¶
func RedisClient(config RedisClientConfig) (*redis.Client, error)
Types ¶
type BinaryTranscoder ¶
type CacheInterface ¶
type CacheInterface[T any] interface { cache.CacheInterface[T] }
type CollectionCache ¶
type CollectionCache[T any] interface { // Exists checks if an item exists in cache by name. This is intended to be faster than Get because it does not decode the item. Exists(ctx context.Context, name string) (bool, error) // Get retrieves an item from cache by name Get(ctx context.Context, name string) (*T, error) // Set stores an item in cache Set(ctx context.Context, item *T) error // SetMany stores multiple items in cache SetMany(ctx context.Context, items []*T) error // Delete removes an item from cache Delete(ctx context.Context, name string) error // DeleteMany removes multiple items from cache DeleteMany(ctx context.Context, names []string) error // ListAll retrieves all cached items ListAll(ctx context.Context) ([]*T, error) // Clear removes all items from cache Clear(ctx context.Context) error // IsValid checks if the cache index is valid IsValid(ctx context.Context) (bool, error) // MarkValid marks the cache as valid with TTL MarkValid(ctx context.Context, ttl time.Duration) error }
CollectionCache defines a generic interface for caching collection entries keyed by name.
func NewRedisCollectionCache ¶
func NewRedisCollectionCache[T any]( config RedisClientConfig, batchSize int, prefix string, nameOf func(*T) (string, error), ) (CollectionCache[T], error)
NewRedisCollectionCache creates a new Redis-backed generic collection cache. prefix is used as the key prefix; indexKey is the marker key used by IsValid/MarkValid.
type CplnCacheEntry ¶
type CplnCacheEntry interface {
encoding.BinaryUnmarshaler
encoding.BinaryMarshaler
}
type CplnRedisStore ¶
type CplnRedisStore[T CplnCacheEntry] struct { redisStore.RedisStore // contains filtered or unexported fields }
func (*CplnRedisStore[T]) Delete ¶
func (c *CplnRedisStore[T]) Delete(ctx context.Context, key any) error
func (*CplnRedisStore[T]) GetType ¶
func (c *CplnRedisStore[T]) GetType() string
func (*CplnRedisStore[T]) GetWithTTL ¶
func (*CplnRedisStore[T]) Invalidate ¶
func (c *CplnRedisStore[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
type EncodedCache ¶
type EncodedCache[T any] struct { // contains filtered or unexported fields }
func (*EncodedCache[T]) Delete ¶
func (r *EncodedCache[T]) Delete(ctx context.Context, key any) error
func (*EncodedCache[T]) Get ¶
func (r *EncodedCache[T]) Get(ctx context.Context, key any) (T, error)
func (*EncodedCache[T]) GetType ¶
func (r *EncodedCache[T]) GetType() string
func (*EncodedCache[T]) Invalidate ¶
func (r *EncodedCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error
type JsonCplnCacheEntry ¶
type JsonCplnCacheEntry[T any] struct { // contains filtered or unexported fields }
func NewJsonCplnCacheEntry ¶
func NewJsonCplnCacheEntry[T any](payload T) *JsonCplnCacheEntry[T]
func (*JsonCplnCacheEntry[T]) MarshalBinary ¶
func (a *JsonCplnCacheEntry[T]) MarshalBinary() (data []byte, err error)
func (*JsonCplnCacheEntry[T]) Payload ¶
func (a *JsonCplnCacheEntry[T]) Payload() T
func (*JsonCplnCacheEntry[T]) UnmarshalBinary ¶
func (a *JsonCplnCacheEntry[T]) UnmarshalBinary(data []byte) error
type JsonTranscoder ¶
type JsonTranscoder[T any] struct { }
func (JsonTranscoder[T]) Decode ¶
func (j JsonTranscoder[T]) Decode(bytes []byte) (T, error)
func (JsonTranscoder[T]) Encode ¶
func (j JsonTranscoder[T]) Encode(t T) ([]byte, error)
type RedisClientConfig ¶
type RedisCollectionCache ¶
type RedisCollectionCache[T any] struct { // contains filtered or unexported fields }
RedisCollectionCache implements CollectionCache using Redis. It is parameterized over the cached type T and uses a configurable key prefix.
func (*RedisCollectionCache[T]) Clear ¶
func (c *RedisCollectionCache[T]) Clear(ctx context.Context) error
func (*RedisCollectionCache[T]) Delete ¶
func (c *RedisCollectionCache[T]) Delete(ctx context.Context, name string) error
func (*RedisCollectionCache[T]) DeleteMany ¶
func (c *RedisCollectionCache[T]) DeleteMany(ctx context.Context, names []string) error
func (*RedisCollectionCache[T]) Get ¶
func (c *RedisCollectionCache[T]) Get(ctx context.Context, name string) (*T, error)
func (*RedisCollectionCache[T]) IsValid ¶
func (c *RedisCollectionCache[T]) IsValid(ctx context.Context) (bool, error)
func (*RedisCollectionCache[T]) ListAll ¶
func (c *RedisCollectionCache[T]) ListAll(ctx context.Context) ([]*T, error)
Click to show internal directories.
Click to hide internal directories.