@Override
    public PublishedItem getPublishedItem( final LeafNode node, final PublishedItem.UniqueIdentifier itemIdentifier )
    {
        flushPendingChanges( node.getUniqueIdentifier() );

        // try to fetch from cache first without locking
        PublishedItem result = itemCache.get(itemIdentifier);
        if (result == null) {
            Lock itemLock = itemCache.getLock( itemIdentifier );
            itemLock.lock();
            try {
                // Acquire lock, then re-check cache before reading from DB;
                // allows clustered item cache to be primed by first request
                result = itemCache.get(itemIdentifier);
                if (result == null) {
                    log.trace("No cached item found. Obtaining it from delegate. Item identifier: {}", itemIdentifier);
                    result = delegate.getPublishedItem( node, itemIdentifier );
                    if (result != null) {
                        log.trace("Caching item obtained from delegate.");
                        itemCache.put(itemIdentifier, result);
                    } else {
                        log.trace("Delegate doesn't have an item. It does not appear to exist.");
                    }
                } else {
                    log.trace("Found cached item on second attempt (after acquiring lock). Item identifier: {}", itemIdentifier);
                }

            } finally {
                itemLock.unlock();
            }
        } else {
            log.trace("Found cached item on first attempt (no lock). Item identifier: {}", itemIdentifier);
        }
        log.debug( "Item for item identifier {} was {} on node {}", itemIdentifier, result == null ? "not found" : "found", node.getUniqueIdentifier() );
        return result;
    }
Persists any changes that have been applied to the caches by invoking the relevant methods of the delegate.

A flush can be performed either local (typically used to periodically persist data) or cluster-wide (useful to
ensure that a particular state is reached, cluster-wide).

@param sendToCluster set to 'true' to trigger a flush on all cluster nodes. If false, a flush will occur only on
                     the local node.
xmppserver/src/main/java/org/jivesoftware/openfire/pubsub/CachingPubsubPersistenceProvider.java