protected Queue<Message> getHistoryFromCache() {
        // Ensure room history is in cache. Doing this outside of the lock below, to reduce the likelihood of deadlocks occurring.
        if (!MUC_HISTORY_CACHE.containsKey(roomJID)) {
            try {
                final MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(roomJID).getChatRoom(roomJID.getNode());
                MUCPersistenceManager.loadHistory(room, getMaxNumber());
            } catch (Exception e) {
                Log.error("Unable to load history for room {} from database.", roomJID, e);
            }
        }

        // Obtain history from cache.
        final Lock lock = MUC_HISTORY_CACHE.getLock(roomJID);
        lock.lock();
        try {
            final CacheableOptional<Messages> optional = MUC_HISTORY_CACHE.get(roomJID);
            if (optional == null || optional.isAbsent()) {
                return new Messages().asCollection();
            } else {
                return optional.get().asCollection();
            }
        } finally {
            lock.unlock();
        }
    }
Obtains the historic messages cached for this particular room from the cache.

This method ensures that a room-based lock is acquired, before interacting with the cache.

Note that modifications applied to the returned collection are not guaranteed to be applied to the cache.
Explicitly put the collection back in the cache to ensure that changes are persisted there.

@return The historic messages for this room.
xmppserver/src/main/java/org/jivesoftware/openfire/muc/HistoryStrategy.java