Documentation
¶
Index ¶
- type Config
- type Store
- func (s *Store[K, V]) All() []*V
- func (s *Store[K, V]) Clear()
- func (s *Store[K, V]) Count(fn func(*V) bool) int
- func (s *Store[K, V]) CountUnlocked(fn func(*V) bool) int
- func (s *Store[K, V]) Delete(key K) error
- func (s *Store[K, V]) DeleteUnlocked(key K) error
- func (s *Store[K, V]) DeletedCount() int
- func (s *Store[K, V]) DirtyCount() int
- func (s *Store[K, V]) Filter(fn func(*V) bool) []*V
- func (s *Store[K, V]) FilterUnlocked(fn func(*V) bool) []*V
- func (s *Store[K, V]) FlushDirty() error
- func (s *Store[K, V]) ForEach(fn func(K, *V))
- func (s *Store[K, V]) Get(key K) (*V, bool)
- func (s *Store[K, V]) GetUnlocked(key K) (*V, bool)
- func (s *Store[K, V]) Len() int
- func (s *Store[K, V]) LoadAll() error
- func (s *Store[K, V]) Lock()
- func (s *Store[K, V]) Put(key K, value *V) error
- func (s *Store[K, V]) PutUnlocked(key K, value *V) error
- func (s *Store[K, V]) RLock()
- func (s *Store[K, V]) RUnlock()
- func (s *Store[K, V]) ReplayDelete(key K)
- func (s *Store[K, V]) ReplayPut(key K, value *V)
- func (s *Store[K, V]) SetWAL(w wal.WAL)
- func (s *Store[K, V]) Unlock()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config[K comparable, V any] struct { Disk *diskstore.DiskStore[V] WAL wal.WAL EntityName string KeyToStr func(K) string // convert key to string for WAL/disk StrToKey func(string) K // convert string back to key }
Config holds the configuration for creating a new Store.
type Store ¶
type Store[K comparable, V any] struct { // contains filtered or unexported fields }
Store is a generic in-memory cache backed by a DiskStore and WAL. All reads are served from memory. Writes go to WAL first, then memory. Dirty records are flushed to disk periodically by the background flusher.
func NewStore ¶
func NewStore[K comparable, V any](cfg Config[K, V]) *Store[K, V]
NewStore creates a new Store. Call LoadAll() after creation to populate from disk, or start empty.
func (*Store[K, V]) All ¶
func (s *Store[K, V]) All() []*V
All returns all records in the store. The returned slice contains pointers to the actual stored records.
func (*Store[K, V]) Clear ¶
func (s *Store[K, V]) Clear()
Clear removes all records from memory without writing to WAL or disk. Used for testing and Drop operations.
func (*Store[K, V]) CountUnlocked ¶
CountUnlocked returns count without acquiring the lock.
func (*Store[K, V]) Delete ¶
Delete removes a record. The change is written to WAL first, then applied to memory.
func (*Store[K, V]) DeleteUnlocked ¶
DeleteUnlocked removes a record without acquiring the lock. The caller must hold the write lock.
func (*Store[K, V]) DeletedCount ¶
DeletedCount returns the number of tombstoned records pending flush.
func (*Store[K, V]) DirtyCount ¶
DirtyCount returns the number of dirty records pending flush.
func (*Store[K, V]) FilterUnlocked ¶
FilterUnlocked returns matching records without acquiring the lock. The caller must hold at least the read lock.
func (*Store[K, V]) FlushDirty ¶
FlushDirty writes all dirty records to disk and removes tombstoned records from disk. Clears the dirty and deleted sets afterward.
func (*Store[K, V]) ForEach ¶
func (s *Store[K, V]) ForEach(fn func(K, *V))
ForEach calls fn for each (key, value) pair in the store.
func (*Store[K, V]) GetUnlocked ¶
GetUnlocked retrieves a record without acquiring the lock. The caller must hold at least the read lock.
func (*Store[K, V]) LoadAll ¶
LoadAll loads all records from disk into memory. This is called during startup to populate the cache. Existing in-memory records are preserved (WAL replay may have already added some).
func (*Store[K, V]) Lock ¶
func (s *Store[K, V]) Lock()
Lock acquires the write lock. Use with Unlock for atomic multi-step operations (e.g. SelectAndAssign). The caller must call Unlock.
func (*Store[K, V]) Put ¶
Put adds or updates a record. The change is written to WAL first, then applied to memory and marked dirty.
func (*Store[K, V]) PutUnlocked ¶
PutUnlocked adds a record without acquiring the lock. The caller must hold the write lock. Used for atomic multi-step operations.
func (*Store[K, V]) ReplayDelete ¶
func (s *Store[K, V]) ReplayDelete(key K)
ReplayDelete removes a record directly from memory without writing to WAL. The caller must hold the write lock. Used during WAL replay.
func (*Store[K, V]) ReplayPut ¶
func (s *Store[K, V]) ReplayPut(key K, value *V)
ReplayPut inserts a record directly into memory without writing to WAL. The caller must hold the write lock. Used during WAL replay to avoid double-logging and deadlocks.