Skip to content

Query Cache support#625

Merged
bradh352 merged 13 commits intoc-ares:mainfrom
bradh352:qcache
Nov 19, 2023
Merged

Query Cache support#625
bradh352 merged 13 commits intoc-ares:mainfrom
bradh352:qcache

Conversation

@bradh352
Copy link
Member

@bradh352 bradh352 commented Nov 18, 2023

This PR implements a query cache at the lowest possible level, the actual dns request and response messages. Only successful and NXDOMAIN responses are cached. The lowest TTL in the response message determines the cache validity period for the response, and is capped at the configuration value for qcache_max_ttl. For NXDOMAIN responses, the SOA record is evaluated.

For a query to match the cache, the opcode, flags, and each question's class, type, and name are all evaluated. This is to prevent matching a cached entry for a subtly different query (such as if the RD flag is set on one request and not another).

For things like ares_getaddrinfo() or ares_search() that may spawn multiple queries, each individual message received is cached rather than the overarching response. This makes it possible for one query in the sequence to be purged from the cache while others still return cached results which means there is no chance of ever returning stale data.

We have had a lot of user requests to return TTLs on all the various parsers like ares_parse_caa_reply(), and likely this is because they want to implement caching mechanisms of their own, thus this PR should solve those issues as well.

Due to the internal data structures we have these days, this PR is less than 500 lines of new code.

Fixes #608

Fix By: Brad House (@bradh352)

@bradh352
Copy link
Member Author

need to write a test case that better validates this, but otherwise i think its good.

@bradh352 bradh352 merged commit 4982f76 into c-ares:main Nov 19, 2023
@bradh352 bradh352 deleted the qcache branch November 21, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add optional caching mechanism based on TTL

1 participant