1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Remove cache from DNSUtils

Caching of DNS RR should happen on the lowest possible layer, not within Smack:
- dnsjava does it's own caching
- resolving via the javax API should use the OS's caching (if any)

We don't need dozens layers of DNS RR caching.
This commit is contained in:
Florian Schmaus 2014-03-26 11:10:09 +01:00
parent 2250944ca6
commit dce0c55011

View file

@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
@ -35,12 +34,6 @@ import org.jivesoftware.smack.util.dns.SRVRecord;
*/ */
public class DNSUtil { public class DNSUtil {
/**
* Create a cache to hold the 100 most recently accessed DNS lookups for a period of
* 10 minutes.
*/
private static Map<String, List<HostAddress>> cache = new Cache<String, List<HostAddress>>(100, 1000*60*10);
private static DNSResolver dnsResolver = null; private static DNSResolver dnsResolver = null;
/** /**
@ -116,16 +109,6 @@ public class DNSUtil {
} }
private static List<HostAddress> resolveDomain(String domain, char keyPrefix) throws Exception { private static List<HostAddress> resolveDomain(String domain, char keyPrefix) throws Exception {
// Prefix the key with 's' to distinguish him from the client domain lookups
String key = keyPrefix + domain;
// Return item from cache if it exists.
if (cache.containsKey(key)) {
List<HostAddress> addresses = cache.get(key);
if (addresses != null) {
return addresses;
}
}
List<HostAddress> addresses = new ArrayList<HostAddress>(); List<HostAddress> addresses = new ArrayList<HostAddress>();
// Step one: Do SRV lookups // Step one: Do SRV lookups
@ -145,9 +128,6 @@ public class DNSUtil {
// Step two: Add the hostname to the end of the list // Step two: Add the hostname to the end of the list
addresses.add(new HostAddress(domain)); addresses.add(new HostAddress(domain));
// Add item to cache.
cache.put(key, addresses);
return addresses; return addresses;
} }