noop.go

 1package noop
 2
 3import (
 4	"context"
 5
 6	"github.com/charmbracelet/soft-serve/server/cache"
 7)
 8
 9func init() {
10	cache.Register("noop", newCache)
11}
12
13type noopCache struct{}
14
15// newCache returns a new Cache.
16func newCache(_ context.Context, _ ...cache.Option) (cache.Cache, error) {
17	return &noopCache{}, nil
18}
19
20// Contains implements Cache.
21func (*noopCache) Contains(_ context.Context, _ string) bool {
22	return false
23}
24
25// Delete implements Cache.
26func (*noopCache) Delete(_ context.Context, _ string) {}
27
28// Get implements Cache.
29func (*noopCache) Get(_ context.Context, _ string) (any, bool) {
30	return nil, false
31}
32
33// Keys implements Cache.
34func (*noopCache) Keys(_ context.Context) []string {
35	return []string{}
36}
37
38// Len implements Cache.
39func (*noopCache) Len(_ context.Context) int64 {
40	return -1
41}
42
43// Set implements Cache.
44func (*noopCache) Set(_ context.Context, _ string, _ any, _ ...cache.ItemOption) {}
45
46var _ cache.Cache = &noopCache{}