cache: a byte budget of 256 bytes per entry bounds the cached answers, evicting by clock, and a full or failed copy is counted instead of swallowed

This commit is contained in:
2026-10-22 08:54:59 +02:00
parent d951d03b7d
commit e4e405f8e9
11 changed files with 344 additions and 96 deletions
+2 -2
View File
@@ -604,13 +604,13 @@ test "S8 case 8: the cache ages a real response and expires it at the boundary"
try testing.expectEqual(@as(u32, 300), class.ttl_seconds);
try testing.expectEqual(false, class.negative);
var cache = try dns_cache.DnsCache.init(testing.allocator, .{ .size = 16, .negative_ttl_max = 3600 });
var cache = try dns_cache.DnsCache.init(testing.allocator, .sized(16));
defer cache.deinit();
var key_buf: [dns_cache.max_key_len]u8 = undefined;
const key = dns_cache.buildKey(&key_buf, "example.com", 1, 1, false, null);
try cache.put(1000, key, response, class);
cache.put(1000, key, response, class);
try testing.expectEqual(@as(u32, 1), cache.len());
var out: [512]u8 = undefined;