diff options
author | Lukáš Ondráček <lukas.ondracek@nic.cz> | 2024-05-07 16:06:23 +0200 |
---|---|---|
committer | Lukáš Ondráček <lukas.ondracek@nic.cz> | 2024-05-07 16:06:23 +0200 |
commit | 3754493f83b41592578417f27483d4ce9c8295bd (patch) | |
tree | d7698d6c92b2de34188e4034f191a5f746477a75 /modules/prefetch/prefetch.lua | |
parent | fixup! rrl: truncating answers when close to limit, dropping over limit (diff) | |
parent | Merge remote-tracking branch 'origin/master' into 6.0 (diff) | |
download | knot-resolver-3754493f83b41592578417f27483d4ce9c8295bd.tar.xz knot-resolver-3754493f83b41592578417f27483d4ce9c8295bd.zip |
Merge remote-tracking branch 'origin/6.0' into rrl-wip
Diffstat (limited to 'modules/prefetch/prefetch.lua')
-rw-r--r-- | modules/prefetch/prefetch.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/prefetch/prefetch.lua b/modules/prefetch/prefetch.lua new file mode 100644 index 00000000..673cf3e5 --- /dev/null +++ b/modules/prefetch/prefetch.lua @@ -0,0 +1,21 @@ +-- SPDX-License-Identifier: GPL-3.0-or-later +-- Speculative prefetching for repetitive and soon-expiring records to reduce latency. +-- @module prefetch +local prefetch = {} + + +prefetch.layer = { + -- Prefetch all expiring (sub-)queries immediately after the request finishes. + -- Doing that immediately is simplest and avoids creating (new) large bursts of activity. + finish = function (_, req) + local qrys = req.rplan.resolved + for i = 0, (tonumber(qrys.len) - 1) do -- size_t doesn't work for some reason + local qry = qrys.at[i] + if qry.flags.EXPIRING == true then + resolve(kres.dname2str(qry.sname), qry.stype, qry.sclass, {'NO_CACHE'}) + end + end + end +} + +return prefetch |