use arena_pool for cache get

This commit is contained in:
Muki Kiboigo
2026-03-26 15:54:49 -07:00
parent 8a4aae406f
commit 74026421d4
4 changed files with 13 additions and 21 deletions

View File

@@ -31,6 +31,7 @@ const RobotStore = @import("Robots.zig").RobotStore;
const WebBotAuth = @import("WebBotAuth.zig");
const Cache = @import("cache/Cache.zig");
const App = @import("../App.zig");
const Runtime = @This();
const Listener = struct {
@@ -46,6 +47,7 @@ const MAX_TICK_CALLBACKS = 16;
allocator: Allocator,
app: *App,
config: *const Config,
ca_blob: ?net_http.Blob,
robot_store: RobotStore,
@@ -202,7 +204,7 @@ fn globalDeinit() void {
libcurl.curl_global_cleanup();
}
pub fn init(allocator: Allocator, config: *const Config) !Runtime {
pub fn init(allocator: Allocator, app: *App, config: *const Config) !Runtime {
globalInit(allocator);
errdefer globalDeinit();
@@ -251,6 +253,7 @@ pub fn init(allocator: Allocator, config: *const Config) !Runtime {
.available = available,
.connections = connections,
.app = app,
.robot_store = RobotStore.init(allocator),
.web_bot_auth = web_bot_auth,
.cache = cache,

View File

@@ -28,9 +28,9 @@ kind: union(enum) {
fs: FsCache,
},
pub fn get(self: *Cache, allocator: std.mem.Allocator, key: []const u8) ?CachedResponse {
pub fn get(self: *Cache, arena: std.mem.Allocator, key: []const u8) ?CachedResponse {
return switch (self.kind) {
inline else => |*c| c.get(allocator, key),
inline else => |*c| c.get(arena, key),
};
}
@@ -187,19 +187,6 @@ pub const CachedMetadata = struct {
.headers = headers,
};
}
pub fn deinit(self: CachedMetadata, allocator: std.mem.Allocator) void {
allocator.free(self.url);
allocator.free(self.content_type);
for (self.headers) |header| {
allocator.free(header.name);
allocator.free(header.value);
}
allocator.free(self.headers);
if (self.vary) |v| v.deinit(allocator);
if (self.etag) |e| allocator.free(e);
if (self.last_modified) |lm| allocator.free(lm);
}
};
pub const CachedData = union(enum) {