Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Read from DNS cache if within TTL #677

Merged
merged 4 commits into from
Apr 8, 2016
Merged

Read from DNS cache if within TTL #677

merged 4 commits into from
Apr 8, 2016

Conversation

erikjohnston
Copy link
Member

No description provided.

@@ -154,6 +156,12 @@ def connect(self, protocolFactory):

@defer.inlineCallbacks
def resolve_service(service_name, dns_client=client, cache=SERVER_CACHE):
cache_entry = cache.get(service_name, None)
if cache_entry:
if all(s.expires > int(time.time()) for s in cache_entry):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I tend to prefer to pass in the current time to these things to make testing easier.

cache = {
service_name: [object()]
service_name: [entry]
}

servers = yield resolve_service(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that resolve_service takes a clock, it might be worth using a mock clock here?
Also might be nice to have a test that checks that things expire.

@erikjohnston
Copy link
Member Author

@NegativeMjark PTAL

@NegativeMjark
Copy link
Contributor

LGTM

@erikjohnston erikjohnston merged commit 79fc4ff into develop Apr 8, 2016
@richvdh richvdh deleted the erikj/dns_cache branch December 1, 2016 14:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants