mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-30 17:18:57 +00:00
use arena_pool for cache get
This commit is contained in:
@@ -55,7 +55,7 @@ pub fn init(allocator: Allocator, config: *const Config) !*App {
|
|||||||
.arena_pool = undefined,
|
.arena_pool = undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
app.network = try Network.init(allocator, config);
|
app.network = try Network.init(allocator, app, config);
|
||||||
errdefer app.network.deinit();
|
errdefer app.network.deinit();
|
||||||
|
|
||||||
app.platform = try Platform.init();
|
app.platform = try Platform.init();
|
||||||
|
|||||||
@@ -293,9 +293,8 @@ pub fn request(self: *Client, req: Request) !void {
|
|||||||
return self.fetchRobotsThenProcessRequest(robots_url, req);
|
return self.fetchRobotsThenProcessRequest(robots_url, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serveFromCache(allocator: std.mem.Allocator, req: Request, cached: *const CachedResponse) !void {
|
fn serveFromCache(req: Request, cached: *const CachedResponse) !void {
|
||||||
const response = Response.fromCached(req.ctx, cached);
|
const response = Response.fromCached(req.ctx, cached);
|
||||||
defer cached.metadata.deinit(allocator);
|
|
||||||
|
|
||||||
if (req.start_callback) |cb| {
|
if (req.start_callback) |cb| {
|
||||||
try cb(response);
|
try cb(response);
|
||||||
@@ -334,7 +333,10 @@ fn serveFromCache(allocator: std.mem.Allocator, req: Request, cached: *const Cac
|
|||||||
fn processRequest(self: *Client, req: Request) !void {
|
fn processRequest(self: *Client, req: Request) !void {
|
||||||
if (self.network.cache) |*cache| {
|
if (self.network.cache) |*cache| {
|
||||||
if (req.method == .GET) {
|
if (req.method == .GET) {
|
||||||
if (cache.get(self.allocator, req.url)) |cached| {
|
const arena = try self.network.app.arena_pool.acquire();
|
||||||
|
defer self.network.app.arena_pool.release(arena);
|
||||||
|
|
||||||
|
if (cache.get(arena, req.url)) |cached| {
|
||||||
log.debug(.browser, "http.cache.get", .{
|
log.debug(.browser, "http.cache.get", .{
|
||||||
.url = req.url,
|
.url = req.url,
|
||||||
.found = true,
|
.found = true,
|
||||||
@@ -342,7 +344,7 @@ fn processRequest(self: *Client, req: Request) !void {
|
|||||||
});
|
});
|
||||||
|
|
||||||
defer req.headers.deinit();
|
defer req.headers.deinit();
|
||||||
return serveFromCache(self.allocator, req, &cached);
|
return serveFromCache(req, &cached);
|
||||||
} else {
|
} else {
|
||||||
log.debug(.browser, "http.cache.get", .{ .url = req.url, .found = false });
|
log.debug(.browser, "http.cache.get", .{ .url = req.url, .found = false });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const RobotStore = @import("Robots.zig").RobotStore;
|
|||||||
const WebBotAuth = @import("WebBotAuth.zig");
|
const WebBotAuth = @import("WebBotAuth.zig");
|
||||||
const Cache = @import("cache/Cache.zig");
|
const Cache = @import("cache/Cache.zig");
|
||||||
|
|
||||||
|
const App = @import("../App.zig");
|
||||||
const Runtime = @This();
|
const Runtime = @This();
|
||||||
|
|
||||||
const Listener = struct {
|
const Listener = struct {
|
||||||
@@ -46,6 +47,7 @@ const MAX_TICK_CALLBACKS = 16;
|
|||||||
|
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
|
|
||||||
|
app: *App,
|
||||||
config: *const Config,
|
config: *const Config,
|
||||||
ca_blob: ?net_http.Blob,
|
ca_blob: ?net_http.Blob,
|
||||||
robot_store: RobotStore,
|
robot_store: RobotStore,
|
||||||
@@ -202,7 +204,7 @@ fn globalDeinit() void {
|
|||||||
libcurl.curl_global_cleanup();
|
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);
|
globalInit(allocator);
|
||||||
errdefer globalDeinit();
|
errdefer globalDeinit();
|
||||||
|
|
||||||
@@ -251,6 +253,7 @@ pub fn init(allocator: Allocator, config: *const Config) !Runtime {
|
|||||||
.available = available,
|
.available = available,
|
||||||
.connections = connections,
|
.connections = connections,
|
||||||
|
|
||||||
|
.app = app,
|
||||||
.robot_store = RobotStore.init(allocator),
|
.robot_store = RobotStore.init(allocator),
|
||||||
.web_bot_auth = web_bot_auth,
|
.web_bot_auth = web_bot_auth,
|
||||||
.cache = cache,
|
.cache = cache,
|
||||||
|
|||||||
17
src/network/cache/Cache.zig
vendored
17
src/network/cache/Cache.zig
vendored
@@ -28,9 +28,9 @@ kind: union(enum) {
|
|||||||
fs: FsCache,
|
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) {
|
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,
|
.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) {
|
pub const CachedData = union(enum) {
|
||||||
|
|||||||
Reference in New Issue
Block a user