mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:27:43 +00:00
LookupServer: Don't cache already-expired DNS answers
This commit is contained in:
parent
174583cda5
commit
d1721c761e
1 changed files with 9 additions and 4 deletions
|
@ -240,13 +240,18 @@ Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, u
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<String> responses;
|
Vector<String, 8> responses;
|
||||||
|
Vector<DNSAnswer, 8> cacheable_answers;
|
||||||
for (auto& answer : response.answers()) {
|
for (auto& answer : response.answers()) {
|
||||||
responses.append(answer.record_data());
|
responses.append(answer.record_data());
|
||||||
|
if (!answer.has_expired())
|
||||||
|
cacheable_answers.append(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_lookup_cache.size() >= 256)
|
if (!cacheable_answers.is_empty()) {
|
||||||
m_lookup_cache.remove(m_lookup_cache.begin());
|
if (m_lookup_cache.size() >= 256)
|
||||||
m_lookup_cache.set(hostname, { request.questions()[0], response.answers() });
|
m_lookup_cache.remove(m_lookup_cache.begin());
|
||||||
|
m_lookup_cache.set(hostname, { request.questions()[0], move(cacheable_answers) });
|
||||||
|
}
|
||||||
return responses;
|
return responses;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue