Trait EventCacheStore

Source
pub trait EventCacheStore: AsyncTraitDeps {
    type Error: Debug + Into<EventCacheStoreError>;

    // Required methods
    fn try_take_leased_lock<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        lease_duration_ms: u32,
        key: &'life1 str,
        holder: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn handle_linked_chunk_updates<'life0, 'life1, 'async_trait>(
        &'life0 self,
        linked_chunk_id: LinkedChunkId<'life1>,
        updates: Vec<Update<Event, Gap>>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn load_all_chunks_metadata<'life0, 'life1, 'async_trait>(
        &'life0 self,
        linked_chunk_id: LinkedChunkId<'life1>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ChunkMetadata>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn load_last_chunk<'life0, 'life1, 'async_trait>(
        &'life0 self,
        linked_chunk_id: LinkedChunkId<'life1>,
    ) -> Pin<Box<dyn Future<Output = Result<(Option<RawChunk<Event, Gap>>, ChunkIdentifierGenerator), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn load_previous_chunk<'life0, 'life1, 'async_trait>(
        &'life0 self,
        linked_chunk_id: LinkedChunkId<'life1>,
        before_chunk_identifier: ChunkIdentifier,
    ) -> Pin<Box<dyn Future<Output = Result<Option<RawChunk<Event, Gap>>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn clear_all_linked_chunks<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn filter_duplicated_events<'life0, 'life1, 'async_trait>(
        &'life0 self,
        linked_chunk_id: LinkedChunkId<'life1>,
        events: Vec<OwnedEventId>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(OwnedEventId, Position)>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn find_event<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        room_id: &'life1 RoomId,
        event_id: &'life2 EventId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Event>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn find_event_relations<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        room_id: &'life1 RoomId,
        event_id: &'life2 EventId,
        filter: Option<&'life3 [RelationType]>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(Event, Option<Position>)>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn get_room_events<'life0, 'life1, 'async_trait>(
        &'life0 self,
        room_id: &'life1 RoomId,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Event>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        room_id: &'life1 RoomId,
        event: Event,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn remove_room<'life0, 'life1, 'async_trait>(
        &'life0 self,
        room_id: &'life1 RoomId,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

An abstract trait that can be used to implement different store backends for the event cache of the SDK.

Required Associated Types§

Source

type Error: Debug + Into<EventCacheStoreError>

The error type used by this event cache store.

Required Methods§

Source

fn try_take_leased_lock<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, lease_duration_ms: u32, key: &'life1 str, holder: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Try to take a lock using the given store.

Source

fn handle_linked_chunk_updates<'life0, 'life1, 'async_trait>( &'life0 self, linked_chunk_id: LinkedChunkId<'life1>, updates: Vec<Update<Event, Gap>>, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

An Update reflects an operation that has happened inside a linked chunk. The linked chunk is used by the event cache to store the events in-memory. This method aims at forwarding this update inside this store.

Source

fn load_all_chunks_metadata<'life0, 'life1, 'async_trait>( &'life0 self, linked_chunk_id: LinkedChunkId<'life1>, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChunkMetadata>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load all of the chunks’ metadata for the given LinkedChunkId.

Chunks are unordered, and there’s no guarantee that the chunks would form a valid linked chunk after reconstruction.

Source

fn load_last_chunk<'life0, 'life1, 'async_trait>( &'life0 self, linked_chunk_id: LinkedChunkId<'life1>, ) -> Pin<Box<dyn Future<Output = Result<(Option<RawChunk<Event, Gap>>, ChunkIdentifierGenerator), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load the last chunk of the LinkedChunk holding all events of the room identified by room_id.

This is used to iteratively load events for the EventCache.

Source

fn load_previous_chunk<'life0, 'life1, 'async_trait>( &'life0 self, linked_chunk_id: LinkedChunkId<'life1>, before_chunk_identifier: ChunkIdentifier, ) -> Pin<Box<dyn Future<Output = Result<Option<RawChunk<Event, Gap>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load the chunk before the chunk identified by before_chunk_identifier of the LinkedChunk holding all events of the room identified by room_id

This is used to iteratively load events for the EventCache.

Source

fn clear_all_linked_chunks<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear persisted events for all the rooms.

This will empty and remove all the linked chunks stored previously, using the above Self::handle_linked_chunk_updates methods. It must also delete all the events’ content, if they were stored in a separate table.

⚠ This is meant only for super specific use cases, where there shouldn’t be any live in-memory linked chunks. In general, prefer using EventCache::clear_all_rooms() from the common SDK crate.

Source

fn filter_duplicated_events<'life0, 'life1, 'async_trait>( &'life0 self, linked_chunk_id: LinkedChunkId<'life1>, events: Vec<OwnedEventId>, ) -> Pin<Box<dyn Future<Output = Result<Vec<(OwnedEventId, Position)>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Given a set of event IDs, return the duplicated events along with their position if there are any.

Source

fn find_event<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, room_id: &'life1 RoomId, event_id: &'life2 EventId, ) -> Pin<Box<dyn Future<Output = Result<Option<Event>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Find an event by its ID in a room.

This method must return events saved either in any linked chunks, or events saved “out-of-band” with the Self::save_event method.

Source

fn find_event_relations<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, room_id: &'life1 RoomId, event_id: &'life2 EventId, filter: Option<&'life3 [RelationType]>, ) -> Pin<Box<dyn Future<Output = Result<Vec<(Event, Option<Position>)>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Find all the events (alongside their position in the room’s linked chunk, if available) that relate to a given event.

The only events which don’t have a position are those which have been saved out-of-band using Self::save_event.

Note: it doesn’t process relations recursively: for instance, if requesting only thread events, it will NOT return the aggregated events affecting the returned events. It is the responsibility of the caller to do so, if needed.

An additional filter can be provided to only retrieve related events for a certain relationship.

This method must return events saved either in any linked chunks, or events saved “out-of-band” with the Self::save_event method.

Source

fn get_room_events<'life0, 'life1, 'async_trait>( &'life0 self, room_id: &'life1 RoomId, ) -> Pin<Box<dyn Future<Output = Result<Vec<Event>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get all events in this room.

This method must return events saved either in any linked chunks, or events saved “out-of-band” with the Self::save_event method.

Source

fn save_event<'life0, 'life1, 'async_trait>( &'life0 self, room_id: &'life1 RoomId, event: Event, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Save an event, that might or might not be part of an existing linked chunk.

If the event has no event id, it will not be saved, and the function must return an Ok result early.

If the event was already stored with the same id, it must be replaced, without causing an error.

Provided Methods§

Source

fn remove_room<'life0, 'life1, 'async_trait>( &'life0 self, room_id: &'life1 RoomId, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remove all data tied to a given room from the cache.

Implementors§