-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstore.go
More file actions
31 lines (27 loc) · 1.04 KB
/
store.go
File metadata and controls
31 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package fido
import (
"context"
"iter"
"time"
)
// Store is the persistence backend interface.
type Store[K comparable, V any] interface {
ValidateKey(key K) error
Get(ctx context.Context, key K) (V, time.Time, bool, error)
Set(ctx context.Context, key K, value V, expiry time.Time) error
Delete(ctx context.Context, key K) error
Cleanup(ctx context.Context, maxAge time.Duration) (int, error)
Flush(ctx context.Context) (int, error)
Len(ctx context.Context) (int, error)
Close() error
}
// PrefixScanner is an optional interface for stores that support efficient prefix iteration.
// Only meaningful for Store[string, V].
type PrefixScanner[V any] interface {
// Keys returns an iterator over keys matching prefix.
// Efficient: only lists keys, does not load values from storage.
Keys(ctx context.Context, prefix string) iter.Seq[string]
// Range returns an iterator over key-value pairs matching prefix.
// More expensive than Keys: loads and decodes values from storage.
Range(ctx context.Context, prefix string) iter.Seq2[string, V]
}