pub struct EntityCache { /* private fields */ }Expand description
Entity cache that maintains full projected entities with LRU eviction.
The cache is populated as mutations flow through the projector, regardless of subscriber state. When a new subscriber connects, they receive snapshots of all cached entities for their requested view.
Implementations§
Source§impl EntityCache
impl EntityCache
Sourcepub fn with_config(config: EntityCacheConfig) -> Self
pub fn with_config(config: EntityCacheConfig) -> Self
Create a new entity cache with custom configuration
Sourcepub fn max_entities_per_view(&self) -> usize
pub fn max_entities_per_view(&self) -> usize
Maximum number of entities cached per view.
Derived sorted view caches are bounded by the same value so they never hold more entities than their source view caches.
pub async fn upsert(&self, view_id: &str, key: &str, patch: Value)
pub async fn upsert_with_append( &self, view_id: &str, key: &str, patch: Value, append_paths: &[String], )
Sourcepub async fn get_all(&self, view_id: &str) -> Vec<(String, Value)>
pub async fn get_all(&self, view_id: &str) -> Vec<(String, Value)>
Get all cached entities for a view.
Returns a vector of (key, entity) pairs for sending as snapshots to new subscribers.
Sourcepub async fn get_after(
&self,
view_id: &str,
cursor: &str,
limit: Option<usize>,
) -> Vec<(String, Value)>
pub async fn get_after( &self, view_id: &str, cursor: &str, limit: Option<usize>, ) -> Vec<(String, Value)>
Get entities with _seq greater than the provided cursor.
Returns entities that have been updated after the given cursor, sorted by _seq in ascending order. Useful for resuming from a specific point in the stream.
Sourcepub async fn get(&self, view_id: &str, key: &str) -> Option<Value>
pub async fn get(&self, view_id: &str, key: &str) -> Option<Value>
Get a specific entity from the cache
Sourcepub async fn remove(&self, view_id: &str, key: &str) -> Option<Value>
pub async fn remove(&self, view_id: &str, key: &str) -> Option<Value>
Remove one entity after a source-wide delete.
Sourcepub fn snapshot_config(&self) -> SnapshotBatchConfig
pub fn snapshot_config(&self) -> SnapshotBatchConfig
Get the snapshot batch configuration
pub async fn clear_all(&self)
Sourcepub async fn dump(&self) -> Vec<(String, Vec<(String, Value)>)>
pub async fn dump(&self) -> Vec<(String, Vec<(String, Value)>)>
Dump every view’s entities for a state snapshot.
Entries are ordered most-recently-used first; Self::hydrate relies
on that to reconstruct LRU eviction order.
Sourcepub async fn hydrate(&self, views: Vec<(String, Vec<(String, Value)>)>)
pub async fn hydrate(&self, views: Vec<(String, Vec<(String, Value)>)>)
Restore entities dumped by Self::dump, preserving LRU order.
Entities are inserted as-is (no merge): a snapshot holds fully projected entities, not patches.