Debian Codegraph @

minidns-client/src/main/java/org/minidns/DnsCache.java

raw
1 /*
2 * Copyright 2015-2020 the original author or authors
3 *
4 * This software is licensed under the Apache License, Version 2.0,
5 * the GNU Lesser General Public License version 2 or later ("LGPL")
6 * and the WTFPL.
7 * You may choose either license to govern your use of this software only
8 * upon the condition that you accept all of the terms of either
9 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL.
10 */
11 package org.minidns;
12
13 import org.minidns.dnsmessage.DnsMessage;
14 import org.minidns.dnsname.DnsName;
15 import org.minidns.dnsqueryresult.CachedDnsQueryResult;
16 import org.minidns.dnsqueryresult.DnsQueryResult;
17
18 /**
19 * Cache for DNS Entries. Implementations must be thread safe.
20 */
21 public abstract class DnsCache {
22
23 public static final int DEFAULT_CACHE_SIZE = 512;
24
25 /**
26 * Add an an dns answer/response for a given dns question. Implementations
27 * should honor the ttl / receive timestamp.
28 * @param query The query message containing a question.
29 * @param result The DNS query result.
30 */
31 public final void put(DnsMessage query, DnsQueryResult result) {
32 putNormalized(query.asNormalizedVersion(), result);
33 }
34
35 protected abstract void putNormalized(DnsMessage normalizedQuery, DnsQueryResult result);
36
37 public abstract void offer(DnsMessage query, DnsQueryResult result, DnsName authoritativeZone);
38
39 /**
40 * Request a cached dns response.
41 * @param query The query message containing a question.
42 * @return The dns message.
43 */
44 public final CachedDnsQueryResult get(DnsMessage query) {
45 return getNormalized(query.asNormalizedVersion());
46 }
47
48 protected abstract CachedDnsQueryResult getNormalized(DnsMessage normalizedQuery);
49
50 }