cache.go

 1package cache
 2
 3import (
 4	"context"
 5	"fmt"
 6)
 7
 8var (
 9	// ErrNotFound is returned when a cache is not found.
10	ErrNotFound = fmt.Errorf("cache not found")
11)
12
13// ItemOption is an option for setting cache items.
14type ItemOption func(Item)
15
16// Item is an interface that represents a cache item.
17type Item interface {
18	item()
19}
20
21// Option is an option for creating new cache.
22type Option func(Cache)
23
24// Cache is a caching interface.
25type Cache interface {
26	Get(ctx context.Context, key string) (value any, ok bool)
27	Set(ctx context.Context, key string, val any, opts ...ItemOption)
28	Keys(ctx context.Context) []string
29	Len(ctx context.Context) int64
30	Contains(ctx context.Context, key string) bool
31	Delete(ctx context.Context, key string)
32}