Skip to content

mdk-memory-storage: unify messages_cache and messages_by_group_cache #255

@dannym-arx

Description

@dannym-arx

Follow-up from @jgmontoya's review on #253 (comment on crates/mdk-memory-storage/src/messages.rs).

Problem

mdk-memory-storage keeps two LRU caches that can diverge:

  • messages_cache: LruCache<EventId, Message> — global index
  • messages_by_group_cache: LruCache<GroupId, BTreeMap<EventId, Message>> — per-group index

Because they have independent eviction, every deletion/read path currently has to double-check both caches (see delete_message, delete_messages_before_timestamp in crates/mdk-memory-storage/src/messages.rs) and merge results. This is fragile and the divergence-handling is spread across every operation.

Proposed directions

  1. Make messages_cache a secondary index mapping EventId → GroupId, with the per-group BTreeMap as the authoritative store. A stale pointer is just a miss — cheap to handle.
  2. Or drop messages_cache entirely and resolve EventId lookups by scanning the per-group map (acceptable if the access pattern is always group-scoped anyway).

Either way, the goal is to eliminate the "look in both, reconcile the difference" pattern that the current deletion code uses.

Context

Raised in review of PR #253 (disappearing messages), which added the deletion APIs that made the divergence visible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions