feat: add count-based upstream verification for cached records#691
feat: add count-based upstream verification for cached records#691iCasture wants to merge 1 commit into
Conversation
Add `cache_verify_every` to trigger upstream verification after consecutive cache hits for the same provider and record. Persist verification counters in `cache_meta.cache_verify_counts`, wire the option through CLI, config loading, schema, and docs, and add coverage for the new behavior.
|
How about use some config like |
|
Thanks, that makes sense. I’ll spend some time on this soon and rework the PR. However, I also noticed another cache-related issue that should probably be fixed as part of the same change. When cache is simply enabled with However, when the cache file path is explicitly configured, for example: "cache": "/tmp/example.cache"then with the v4.1 multi-provider config format, multiple provider entries may write into the same cache file. The current cache key is only based on For example: {
"$schema": "https://ddns.newfuture.cc/schema/v4.1.json",
"ssl": true,
"cache": "/tmp/example.cache",
"providers": [
{
"provider": "alidns",
"id": "ACCESSKEY_ID",
"token": "ACCESSKEY_SECRET",
"ipv4": ["example.com"],
"index4": ["regex:200\\.10\\..*"],
"line": "telecom"
},
{
"provider": "alidns",
"id": "ACCESSKEY_ID",
"token": "ACCESSKEY_SECRET",
"ipv4": ["example.com"],
"index4": ["regex:200\\.20\\..*"],
"line": "unicom"
}
]
}In AliDNS, these are actually two different A records: one for the telecom line pointing to But the current cache file may end up like this: {
"example.com:A": "200.20.1.1"
}So the telecom record and the unicom record are sharing the same cache key and one can overwrite the other. The cache should really be able to store both records separately. There is a similar issue for TTL as well. If only the TTL in the config is changed, the old cached value may keep the record from being updated until the cache expires after 72 hours, or until the cache file is manually removed. So I think the current cache key is missing some identity information. For I see two possible ways to handle this:
Which approach do you prefer, or do you have a better idea? |
When cache is enabled, DDNS currently skips upstream checks as long as the resolved local IP has not changed. This means external changes to the upstream DNS record may remain unsynchronized.
This change adds
cache_verify_everyto force one upstream verification after N consecutive cache hits for the same provider and record. The default remains0, so existing behavior is unchanged unless the option is configured.The verification counters are persisted in the existing cache file under
cache_meta.cache_verify_counts, and the option is supported in CLI, JSON config, environment variables, and v4.1 multi-provider configs.Tests and related docs were updated accordingly.