From: Marek VavruĊĦa Date: Sat, 18 Jul 2015 22:55:48 +0000 (+0200) Subject: layer/rrcache: minttl 5s default X-Git-Tag: v1.0.0-beta1~72^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71f20c5663bb37a6c128c468d6a5118c0b3696a5;p=thirdparty%2Fknot-resolver.git layer/rrcache: minttl 5s default --- diff --git a/lib/layer/rrcache.c b/lib/layer/rrcache.c index adc77a8ab..65b0596a5 100644 --- a/lib/layer/rrcache.c +++ b/lib/layer/rrcache.c @@ -26,6 +26,7 @@ #include "lib/module.h" #define DEBUG_MSG(fmt...) QRDEBUG(kr_rplan_current(rplan), " rc ", fmt) +#define DEFAULT_MINTTL (5) /* Short-time "no data" retention to avoid bursts */ static int begin(knot_layer_t *ctx, void *module_param) { @@ -125,15 +126,22 @@ struct stash_baton { struct kr_cache_txn *txn; unsigned timestamp; + uint32_t min_ttl; }; static int commit_rr(const char *key, void *val, void *data) { knot_rrset_t *rr = val; struct stash_baton *baton = data; - if (knot_rrset_ttl(rr) < 1) { - return kr_ok(); /* Ignore cache busters */ + /* Ensure minimum TTL */ + knot_rdata_t *rd = rr->rrs.data; + for (uint16_t i = 0; i < rr->rrs.rr_count; ++i) { + if (knot_rdata_ttl(rd) < baton->min_ttl) { + knot_rdata_set_ttl(rd, baton->min_ttl); + } + rd = kr_rdataset_next(rd); } + /* Check if already cached */ /** @todo This should check if less trusted data is in the cache, for that the cache would need to trace data trust level. @@ -154,7 +162,8 @@ static int stash_commit(map_t *stash, unsigned timestamp, struct kr_cache_txn *t { struct stash_baton baton = { .txn = txn, - .timestamp = timestamp + .timestamp = timestamp, + .min_ttl = DEFAULT_MINTTL }; return map_walk(stash, &commit_rr, &baton); }