s3-orchestrator

syncutil

import "github.com/afreidah/s3-orchestrator/internal/util/syncutil"

Package syncutil provides small concurrency primitives the rest of the codebase shares: AtomicConfig wraps atomic.Pointer[T] for hot-reloadable config, and TTLCache implements a generic time-bounded cache with background eviction.

Index

type AtomicConfig

AtomicConfig is a generic thread-safe holder for a pointer to T. It wraps atomic.Pointer[T] for hot-reloadable configuration or any value that must be read and written concurrently without a mutex. The zero value is usable; Load returns nil before any Store.

type AtomicConfig[T any] struct {
    // contains filtered or unexported fields
}

func (*AtomicConfig[T]) Load

func (a *AtomicConfig[T]) Load() *T

Load atomically returns the current pointer, or nil if none was stored.

func (*AtomicConfig[T]) Store

func (a *AtomicConfig[T]) Store(val *T)

Store atomically replaces the stored pointer.

type TTLCache

TTLCache is a generic in-memory cache with time-based expiry and background eviction. The zero value is not usable; create instances with NewTTLCache.

type TTLCache[K comparable, V any] struct {
    // contains filtered or unexported fields
}

func NewTTLCache

func NewTTLCache[K comparable, V any](ttl time.Duration) *TTLCache[K, V]

NewTTLCache creates a cache with the given default TTL. If ttl > 0, a background goroutine sweeps expired entries at the TTL interval.

func (*TTLCache[K, V]) Clear

func (c *TTLCache[K, V]) Clear()

Clear removes all entries from the cache.

func (*TTLCache[K, V]) Close

func (c *TTLCache[K, V]) Close()

Close stops the background eviction goroutine. Safe to call multiple times.

func (*TTLCache[K, V]) Delete

func (c *TTLCache[K, V]) Delete(key K)

Delete removes a single key from the cache.

func (*TTLCache[K, V]) Get

func (c *TTLCache[K, V]) Get(key K) (V, bool)

Get returns the cached value for the key, or the zero value and false if the key is missing or expired.

func (*TTLCache[K, V]) Len

func (c *TTLCache[K, V]) Len() int

Len returns the number of entries in the cache, including expired entries that have not yet been swept by the background eviction goroutine.

func (*TTLCache[K, V]) Set

func (c *TTLCache[K, V]) Set(key K, value V)

Set stores a key-value pair with the cache’s default TTL.

func (*TTLCache[K, V]) SetWithTTL

func (c *TTLCache[K, V]) SetWithTTL(key K, value V, ttl time.Duration)

SetWithTTL stores a key-value pair with a custom TTL. Use this when callers need per-entry TTL variation (e.g. jitter to prevent expiry storms).

Generated by gomarkdoc