Documentation
¶
Overview ¶
Package cache defines a generic key-value cache interface used across the TNET project — HTTP response caching, and (as consumers migrate) DNS responses, routes, and other []byte-serializable data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("cache: key not found")
ErrNotFound is returned by Cache.Get when the key does not exist. An expired-but-present entry is NOT a miss: it is returned with a non-nil Entry (Expired() == true) so callers can implement serve-stale.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Get returns the entry for key, or ErrNotFound if the key is absent.
Get(ctx context.Context, key string) (*Entry, error)
// Set stores data under key with the given options.
Set(ctx context.Context, key string, data []byte, opts ...SetOption) error
// Delete removes key from the cache. Deleting an absent key is a no-op.
Delete(ctx context.Context, key string) error
}
Cache is a concurrency-safe []byte key-value store. Implementations must be safe for concurrent use.
Get returns ErrNotFound only when the key is absent; an expired entry is returned (with Expired() == true) to support serve-stale.
type Entry ¶
type Entry struct {
// Data is the cached payload. Callers serialize/deserialize their own types.
Data []byte
// Expiration is the absolute expiry time. A zero value means the entry
// never expires.
Expiration time.Time
}
Entry is a single cached value with an expiration time.
type SetOption ¶
type SetOption func(opts *SetOptions)
SetOption is a functional option for configuring SetOptions.
type SetOptions ¶
type SetOptions struct {
// TTL is the time to live for the entry. A non-positive TTL uses the
// cache's default TTL.
TTL time.Duration
}
SetOptions holds parameters for a Set call.