Before: the entire history, the state of the rooms are cached. When opening the chat again, 5 messages are reloaded to the chats in an asynchronous order with the cache. (Maximum 4 times), or until it finds the last message from the cache by id. The requests are separated with a timeout of 500ms.
After:
No more than 30 messages in the cache, so that additional downloads work optimally and during the user's idle state.
This will solve the issue of updating old messages, because keeping about the entire history will not be very correct.
Afterwards we keep improving the caching logic until the moment when we have the most messages cached and performance optimized.