It would be nice to have something similar to what {neo,}mutt has:
https://gitlab.com/muttmua/mutt/-/wikis/MuttGuide/Caching
It is a requirement for sorting emails by threads (based on In-reply-to headers).
Some random thoughts:
Possible candidates for a key-value lib:
IMAP messages are identified by a UID, this would be the "key" and the "value" would be the headers of that message.
For threading support, we need another index where the "key" is the
Message-ID
header value, and "value" is the whole headers of the message. Duplicate values from the UID cache, but I don't think there is a way around this. Having such an index would eliminate the need for IMAP THREAD support. Also, it could be reused for Maildir threading support.