For maximum performance, you can load the entire .xdb file into memory. This allows for completely memory-based queries.
Workflow:
- Load content using
xdb.load_content(db_path). - Create a searcher using
xdb.new_with_buffer(version, content).
Concurrency Note: Unlike the file-based approach, query objects created with the entire xdb cache can be safely used concurrently. It is recommended to create a single global searcher object at startup and use it globally.
local xdb = require("xdb_searcher")
-- Load entire file into memory once
local content = xdb.load_content(db_path)
-- Create a global searcher for concurrent use
local searcher, err = xdb.new_with_buffer(xdb.IPv4, content)
-- ... query ...
searcher:close()
xdb.cleanup()