Sometimes the same entity and node pair is queried multiple times in a brief period. Assuming that entities typically do not change their disco#info and disco#items related capabilities, we could avoid a network I/O if Smack would cache the results for a short period (30 seconds, 1 minute, 5 minutes),
Note that until DiscoverInfo and DiscoverItems is mutable, the need to return cloned instances of the classes.
Methods where the caches should be plugged in
ServiceDiscoveryManager.discoverInfo(Jid, String)
ServiceDiscoveryManager.discoverItems(Jid, String)
Introducing caching may cause inconsistency issues. I suspect those are especially problematic for disco#items. Hence this feature should be introduced with a knob to enable and disable it. Potentially even a matrix setting where one dimension is disco#info and disco#items, and the other one is without-node and with-node.
Links:
https://github.com/Flowdalic/Smack/pull/21#issuecomment-471281503
Branch:
https://github.com/Flowdalic/Smack/tree/disco-info-items-cache