Documentation
¶
Overview ¶
Package cache provides shared distributed caching infrastructure.
It centralizes the TTL-bucketed key lifecycle used by groupcache-based distributed caches throughout parsec, ensuring consistent clock injection, key formatting, and time-bucket rounding.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendTTLSuffix ¶
AppendTTLSuffix appends a time-bucketed TTL suffix to a cache key. The timestamp is rounded down to the nearest TTL interval so that keys naturally "expire" when the current time crosses into the next bucket. If ttl is zero or negative, the key is returned unchanged.
func RoundTimestampToInterval ¶
RoundTimestampToInterval rounds a timestamp down to the nearest interval boundary. If interval is zero or negative, t is returned unchanged. For example, with a 5-minute interval:
- 10:02:30 → 10:00:00
- 10:05:00 → 10:05:00
- 10:07:30 → 10:05:00
func StripTTLSuffix ¶
StripTTLSuffix removes the trailing ":ttl:<timestamp>" suffix appended by AppendTTLSuffix. It trims only the last marker so that keys whose body happens to contain a literal ":ttl:" substring are preserved intact. If the marker is not present, the key is returned unchanged.
Types ¶
type GroupcacheAdapter ¶
GroupcacheAdapter wraps a groupcache group with typed key/value serialization and TTL-bucketed cache keys.
K is the domain key type (e.g. ValidatorInput, *DataSourceInput). V is the domain value type (e.g. *Result, *cachedEntry).
func NewGroupcacheAdapter ¶
func NewGroupcacheAdapter[K any, V any]( groupName string, serializeKey func(K) (string, error), deserializeKey func(string) (K, error), fetch func(context.Context, K) (V, error), serializeValue func(V) ([]byte, error), deserializeValue func([]byte) (V, error), opts ...GroupcacheAdapterOption, ) (*GroupcacheAdapter[K, V], error)
NewGroupcacheAdapter creates a GroupcacheAdapter.
Required parameters are positional: groupName uniquely identifies the groupcache group within the process, and the serialize/deserialize/fetch functions handle domain-type conversion and origin fetches.
type GroupcacheAdapterOption ¶
type GroupcacheAdapterOption func(*groupcacheAdapterConfig)
GroupcacheAdapterOption configures optional behavior of a GroupcacheAdapter.
func WithCacheSizeBytes ¶
func WithCacheSizeBytes(n int64) GroupcacheAdapterOption
WithCacheSizeBytes sets the maximum cache size in bytes. Default: 64 MB.
func WithClock ¶
func WithClock(c clock.Clock) GroupcacheAdapterOption
WithClock sets the clock used for TTL bucketing. Default: clock.NewSystemClock.
func WithTTL ¶
func WithTTL(ttl func() TTL) GroupcacheAdapterOption
WithTTL sets the function that returns the time-to-live for cached entries. Called on each Get to allow dynamic TTL (though typically static). If not set, entries are cached indefinitely.