pub struct ForeignRecords {
pub(crate) fetcher: Arc<dyn Fetch>,
pub(crate) limits: Limits,
pub(crate) cache: Mutex<LruCache<String, Entry>>,
pub(crate) hits: AtomicU64,
pub(crate) misses: AtomicU64,
pub(crate) unknowns: AtomicU64,
pub(crate) refusals: AtomicU64,
}Expand description
The reader: a bounded cache of foreign records, over one Fetch.
Deployment-wide, not per session: plan/ai-preference.md’s “one
resolver, one cache, deployment-wide” is the whole difference between
being a good guest on somebody else’s server and being the traffic that
gets a deployment defederated.
Fields§
§fetcher: Arc<dyn Fetch>§limits: Limits§cache: Mutex<LruCache<String, Entry>>§hits: AtomicU64§misses: AtomicU64§unknowns: AtomicU64§refusals: AtomicU64Implementations§
Source§impl ForeignRecords
impl ForeignRecords
Sourcepub fn new(fetcher: Arc<dyn Fetch>, limits: Limits) -> Self
pub fn new(fetcher: Arc<dyn Fetch>, limits: Limits) -> Self
A reader over fetcher, bounded by limits.
An entries of zero holds one entry: a cache that holds nothing
would make every read a fetch, which is the traffic pattern this
crate exists to avoid.
Sourcepub fn over_network(
local: Arc<dyn LocalRepositories>,
private: PrivateAddresses,
limits: Limits,
) -> Self
pub fn over_network( local: Arc<dyn LocalRepositories>, private: PrivateAddresses, limits: Limits, ) -> Self
A reader over the real network, refusing what local already holds
and refusing a private address unless private allows one.
Sourcepub fn read(&self, record: &RecordRef) -> Answer
pub fn read(&self, record: &RecordRef) -> Answer
The answer held for record.
Performs no I/O and never awaits, so an evaluator may call it from
inside a decision. A record nothing has fetched, and one whose
answer has aged out, are both Unknown::NotFetched.
Sourcepub async fn prefetch(&self, wanted: &[RecordRef])
pub async fn prefetch(&self, wanted: &[RecordRef])
Fetches every record in wanted the cache holds no fresh answer
for, and caches what comes back.
Bounded three ways: at most Limits::per_write records are
fetched, each fetch by Limits::record_deadline, and the whole
call by Limits::prefetch_deadline. A record the budget does not
reach is cached as Unknown::Deadline, so the write that asked
gets an answer either way and the next write does not queue behind
the same dead server.