Skip to main content

ForeignRecords

Struct ForeignRecords 

Source
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: AtomicU64

Implementations§

Source§

impl ForeignRecords

Source

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.

Source

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.

Source

pub fn limits(&self) -> Limits

What this reader is bounded by.

Source

pub fn counts(&self) -> Counts

What this reader has done since the process started.

Source

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.

Source

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.

Source

pub async fn get(&self, record: &RecordRef) -> Answer

prefetch for one record, then read of it — for a caller that has a runtime and wants the answer now rather than at a later decision.

Source

pub(crate) fn fresh(&self, key: &str) -> bool

Whether the cache holds an answer for key that has not expired. Does not count as a read: a prefetch skipping a record it already holds is not an evaluator asking for one.

Source

pub(crate) fn store(&self, record: &RecordRef, fetched: Fetched)

Caches one fetch’s outcome under record’s at-uri, for the TTL its kind of answer gets, and counts it.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more