@Override
    public void savePublishedItem(PublishedItem item) {
        log.debug( "Saving published item {} {}", item.getNode().getUniqueIdentifier(), item.getID() );

        PublishedItem.UniqueIdentifier itemKey = item.getUniqueIdentifier();
        itemCache.put(itemKey, item);
        log.debug("Added new (inbound) item to cache");
        synchronized (itemsPending) {
            PublishedItem itemToReplace = itemsPending.remove(itemKey);
            if (itemToReplace != null) {
                itemsToAdd.remove(itemToReplace); // remove duplicate from itemsToAdd linked list
            }

            // TODO this iterates over all elements in the collection. See if this can be improved for performance.
            itemsToDelete.removeIf(scheduledItem -> item.getUniqueIdentifier().equals(scheduledItem.getUniqueIdentifier()));

            itemsToAdd.addLast(item);
            itemsPending.put(itemKey, item);
        }

        if (itemsPending.size() > MAX_ITEMS_FLUSH) {
            TaskEngine.getInstance().submit(() -> flushPendingChanges(false));
        }
    }
Cache for recently accessed published items.
xmppserver/src/main/java/org/jivesoftware/openfire/pubsub/CachingPubsubPersistenceProvider.java