Sourcing::Plugin::StateCache
Abstract role defining the interface for state caching backends. State caches handle the storage and retrieval of projection state for faster recovery and reduced event replay overhead.
Overview
The StateCache role handles projection state persistence:
- State storage — caching projection state to avoid full replay
- State retrieval — fetching cached state for fast recovery
- Version tracking — tracking the last processed event ID
See also: Sourcing::Plugin::EventStore for the event storage interface.
Abstract Methods
method store-cached-data(Mu:U, %)
Stores the current state and version of a projection. Implementations should persist the projection data along with the last processed event ID.
| Parameter | Type | Description |
|---|---|---|
Mu:U | Type | The projection type |
% | Hash | Additional data to cache (IDs, state, etc.) |
method get-cached-data(Mu:U, %) is rw
Retrieves the cached state and version for a projection. Returns a Hash with last-id and data keys.
| Parameter | Type | Description |
|---|---|---|
Mu:U | Type | The projection type |
% | Hash | Identity criteria |
Returns: A Hash with:
last-id— The last processed event version (atomicint, defaults to -1)data— The cached projection state (Hash)
Class Methods
method use(|c)
Activates this plugin as the current sourcing configuration by setting PROCESS::<$SourcingConfig>.
Sourcing::Plugin::StateCache::Memory.use;
Use Cases
State caching is particularly useful for:
- Fast recovery — Load cached state instead of replaying all events
- Read performance — Serve cached projections for high-read scenarios
- Hybrid approaches — Use different backends for events vs. state
See Also
- Sourcing::Plugin::StateCache::Memory — the built-in in-memory implementation
- Sourcing::Plugin::EventStore — the event storage interface
- Sourcing::Plugin::Memory — combined implementation
- Writing a Plugin Guide — how to implement your own plugin