Versions in this module Expand all Collapse all v0 v0.1.0 Aug 31, 2026 Changes in this version + const DefaultCleanupInterval + const DefaultExpiration + const DefaultPersistInterval + const NoExpiration + var ErrClosed = errors.New("ttlmap: map is closed") + var ErrCorruptSnapshot = errors.New("ttlmap: corrupt snapshot") + var ErrPersistenceAlreadyEnabled = errors.New("ttlmap: persistence already enabled") + var ErrPersistenceNotEnabled = errors.New("ttlmap: persistence not enabled") + var ErrSnapshotLockUnsupported = errors.New("ttlmap: snapshot locking unsupported on this platform") — js/wasm + var ErrSnapshotSync = errors.New("ttlmap: snapshot published but directory sync failed") + var ErrSnapshotTooLarge = errors.New("ttlmap: snapshot exceeds configured limits") + var ErrUnsupportedSnapshot = errors.New("ttlmap: unsupported snapshot version") + type BinaryCodec struct + func (BinaryCodec[K, V]) MarshalKey(k K) ([]byte, error) + func (BinaryCodec[K, V]) MarshalValue(v V) ([]byte, error) + func (BinaryCodec[K, V]) UnmarshalKey(b []byte) (K, error) + func (BinaryCodec[K, V]) UnmarshalValue(b []byte) (V, error) + type Clock interface + Now func() time.Time + type Codec interface + MarshalKey func(K) ([]byte, error) + MarshalValue func(V) ([]byte, error) + UnmarshalKey func([]byte) (K, error) + UnmarshalValue func([]byte) (V, error) + type JSONCodec struct + func (JSONCodec[K, V]) MarshalKey(k K) ([]byte, error) + func (JSONCodec[K, V]) MarshalValue(v V) ([]byte, error) + func (JSONCodec[K, V]) UnmarshalKey(b []byte) (K, error) + func (JSONCodec[K, V]) UnmarshalValue(b []byte) (V, error) + type Map struct + func Load[K comparable, V any](r io.Reader, codec Codec[K, V], defaultTTL time.Duration, opts ...Option) (*Map[K, V], error) + func New[K comparable, V any](defaultTTL time.Duration, opts ...Option) *Map[K, V] + func Open[K comparable, V any](defaultTTL time.Duration, cfg PersistConfig[K, V], opts ...Option) (*Map[K, V], error) + func (m *Map[K, V]) All() iter.Seq2[K, V] + func (m *Map[K, V]) Clear() + func (m *Map[K, V]) Close() error + func (m *Map[K, V]) DefaultTTL() time.Duration + func (m *Map[K, V]) Delete(key K) + func (m *Map[K, V]) DeleteExpired() int + func (m *Map[K, V]) EnablePersistence(cfg PersistConfig[K, V]) error + func (m *Map[K, V]) Get(key K) (V, bool) + func (m *Map[K, V]) GetOrSet(key K, value V, ttl time.Duration) (V, bool) + func (m *Map[K, V]) GetTTL(key K) (time.Duration, bool) + func (m *Map[K, V]) GetWithTTL(key K) (V, time.Duration, bool) + func (m *Map[K, V]) Has(key K) bool + func (m *Map[K, V]) LoadAndDelete(key K) (V, bool) + func (m *Map[K, V]) MGet(keys ...K) map[K]V + func (m *Map[K, V]) MSet(values map[K]V, ttl time.Duration) + func (m *Map[K, V]) Peek(key K) (V, bool) + func (m *Map[K, V]) PersistErr() error + func (m *Map[K, V]) PersistenceEnabled() bool + func (m *Map[K, V]) Range(f func(key K, value V) bool) + func (m *Map[K, V]) Save() error + func (m *Map[K, V]) SaveFile(path string, codec Codec[K, V]) error + func (m *Map[K, V]) Set(key K, value V, ttl time.Duration) + func (m *Map[K, V]) SetIfAbsent(key K, value V, ttl time.Duration) bool + func (m *Map[K, V]) SetTTL(key K, ttl time.Duration) bool + func (m *Map[K, V]) Size() int + func (m *Map[K, V]) Update(key K, ttl time.Duration, fn func(V) V) (v V, ok bool) + func (m *Map[K, V]) WriteSnapshot(w io.Writer, codec Codec[K, V]) error + type Option func(*options) + func WithCapacity(sizeHint int) Option + func WithCleanupInterval(d time.Duration) Option + func WithClock(c Clock) Option + type PersistConfig struct + Codec Codec[K, V] + Interval time.Duration + NoSync bool + OnError func(error) + Path string + type StringBinaryCodec struct + func (StringBinaryCodec[V]) MarshalKey(k string) ([]byte, error) + func (StringBinaryCodec[V]) MarshalValue(v V) ([]byte, error) + func (StringBinaryCodec[V]) UnmarshalKey(b []byte) (string, error) + func (StringBinaryCodec[V]) UnmarshalValue(b []byte) (V, error) + type StringBytesCodec struct + func (StringBytesCodec) MarshalKey(k string) ([]byte, error) + func (StringBytesCodec) MarshalValue(v []byte) ([]byte, error) + func (StringBytesCodec) UnmarshalKey(b []byte) (string, error) + func (StringBytesCodec) UnmarshalValue(b []byte) ([]byte, error)