Documentation
¶
Index ¶
- Variables
- type Cache
- type ChainStore
- func (c *ChainStore) Clear(ctx context.Context) error
- func (c *ChainStore) Close() error
- func (c *ChainStore) Delete(ctx context.Context, key string) error
- func (c *ChainStore) DeleteMany(ctx context.Context, keys []string) error
- func (c *ChainStore) Get(ctx context.Context, key string) (any, error)
- func (c *ChainStore) GetMany(ctx context.Context, keys []string) (map[string]any, error)
- func (c *ChainStore) Set(ctx context.Context, key string, value any, opts ...Option) error
- type Option
- type Options
- type Store
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotFound = errors.New("xcache: key not found")
ErrNotFound is returned when a key is not found or has expired.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] interface { Get(ctx context.Context, key string) (T, error) Set(ctx context.Context, key string, value T, opts ...Option) error Delete(ctx context.Context, key string) error Clear(ctx context.Context) error GetOrLoad(ctx context.Context, key string, loader func(ctx context.Context) (T, error), opts ...Option) (T, error) GetMany(ctx context.Context, keys []string) (map[string]T, error) DeleteMany(ctx context.Context, keys []string) error }
type ChainStore ¶
type ChainStore struct {
// contains filtered or unexported fields
}
ChainStore esegue le operazioni in cascata su una lista di Store (es. L1→L2). Get cerca nell'ordine: primo store che risponde vince. Set e Delete propagano a tutti gli store.
func NewChain ¶
func NewChain(stores ...Store) *ChainStore
func (*ChainStore) Close ¶
func (c *ChainStore) Close() error
func (*ChainStore) DeleteMany ¶
func (c *ChainStore) DeleteMany(ctx context.Context, keys []string) error
type Options ¶
type Options struct {
TTL time.Duration // 0 means no expiration
Tags []string // Invalidates all keys with any of these tags when deleted
}
func ApplyOptions ¶
applyOptions applies the given options and returns the resulting Options struct.
type Store ¶
type Store interface {
Get(ctx context.Context, key string) (any, error)
Set(ctx context.Context, key string, value any, opts ...Option) error
Delete(ctx context.Context, key string) error
Clear(ctx context.Context) error
Close() error
GetMany(ctx context.Context, keys []string) (map[string]any, error)
DeleteMany(ctx context.Context, keys []string) error
}
Click to show internal directories.
Click to hide internal directories.