#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)
{
{
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.
{
struct stash_baton baton = {
.txn = txn,
- .timestamp = timestamp
+ .timestamp = timestamp,
+ .min_ttl = DEFAULT_MINTTL
};
return map_walk(stash, &commit_rr, &baton);
}