| Copyright | (c) 2024 |
|---|---|
| License | BSD3 |
| Maintainer | maintainer@example.com |
| Stability | experimental |
| Safe Haskell | None |
| Language | GHC2021 |
Hindsight.Store.Memory
Description
Overview
In-memory event store using STM (Software Transactional Memory) for fast, concurrent access. Ideal for testing, development, and scenarios where events don't need to survive process restarts.
⚠️ Data is lost on process termination - not suitable for production use.
Quick Start
import Hindsight.Store.Memory (newMemoryStore) import Hindsight main :: IO () main = do -- Create store store <- newMemoryStore -- Insert events (see Hindsight.Store for details) streamId <- StreamId <$> UUID.nextRandom let event = mkEvent MyEvent myData result <- insertEvents store Nothing $ singleEvent streamId NoStream event -- Subscribe to events handle <- subscribe store matcher (EventSelector AllStreams FromBeginning) -- ... process events ...
Use Cases
When to use Memory store:
- Unit and integration tests (fast, isolated)
- Development and prototyping
- Temporary event processing pipelines
- Scenarios where persistence isn't required
When NOT to use Memory store:
- Production systems requiring durability
- Multi-process applications (each process has separate state)
- Long-running services that can't afford data loss
Trade-offs
Advantages:
- Fastest performance (no I/O)
- No external dependencies
- Simple setup (single function call)
- Thread-safe via STM
Limitations:
- Data lost on process termination or crash
- Memory usage grows with event count
- Single-process only (no sharing between instances)
- No built-in persistence or snapshots
Implementation
Events and stream metadata stored in-memory using STM TVars.
Subscriptions use STM retry mechanism for efficient event notification.
Synopsis
- data MemoryStore
- data MemoryStoreHandle
- newtype MemoryCursor = MemoryCursor {}
- newMemoryStore :: IO MemoryStoreHandle
- module Hindsight.Store
Core Types
data MemoryStore Source #
Instances
| EventStore MemoryStore Source # | Memory store implementation | ||||
Defined in Hindsight.Store.Memory Associated Types
Methods insertEvents :: forall (t :: Type -> Type) m. (Traversable t, StoreConstraints MemoryStore m) => BackendHandle MemoryStore -> Maybe CorrelationId -> Transaction t MemoryStore -> m (InsertionResult MemoryStore) # subscribe :: forall m (ts :: [Symbol]). StoreConstraints MemoryStore m => BackendHandle MemoryStore -> EventMatcher ts MemoryStore m -> EventSelector MemoryStore -> m (SubscriptionHandle MemoryStore) # | |||||
| StoreCursor MemoryStore Source # | |||||
Defined in Hindsight.Store.Memory Methods makeCursor :: Integer -> Cursor MemoryStore Source # | |||||
| type BackendHandle MemoryStore Source # | |||||
Defined in Hindsight.Store.Memory | |||||
| type Cursor MemoryStore Source # | Type family instances | ||||
Defined in Hindsight.Store.Memory | |||||
| type StoreConstraints MemoryStore m Source # | |||||
Defined in Hindsight.Store.Memory | |||||
data MemoryStoreHandle Source #
Handle for the memory store
newtype MemoryCursor Source #
Cursor implementation for the memory store
Constructors
| MemoryCursor | |
Fields | |
Instances
Store Operations
newMemoryStore :: IO MemoryStoreHandle Source #
Creates a new memory store instance
Re-exports
module Hindsight.Store