Skip to main content

CacheMeta

Struct CacheMeta 

Source
pub struct CacheMeta(/* private fields */);
Expand description

The cacheable response header and cache metadata

Implementations§

Source§

impl CacheMeta

Source

pub fn new( fresh_until: SystemTime, created: SystemTime, stale_while_revalidate_sec: u32, stale_if_error_sec: u32, header: ResponseHeader, ) -> CacheMeta

Create a CacheMeta from the given metadata and the response header

Source

pub fn created(&self) -> SystemTime

When the asset was created/admitted to cache

Source

pub fn updated(&self) -> SystemTime

The last time the asset was revalidated

This value will be the same as Self::created() if no revalidation ever happens

Source

pub fn provenance(&self) -> SystemTime

Cache-object provenance timestamp.

When populated, this is a stable reference point for the cache object’s lineage that hit filtering code can use instead of relying on the metadata record’s creation time. The accessor falls back to Self::created while the field is absent.

Source

pub fn epoch(&self) -> SystemTime

The reference point for cache age. This represents the “starting point” for fresh_until.

This defaults to the updated timestamp but is overridden by the epoch_override field if set.

Source

pub fn epoch_override(&self) -> Option<SystemTime>

Get the epoch override for this asset

Source

pub fn set_epoch_override(&mut self, epoch: SystemTime)

Set the epoch override for this asset

When set, this will be used as the reference point for calculating age and freshness instead of the updated time.

Source

pub fn remove_epoch_override(&mut self)

Remove the epoch override for this asset

Source

pub fn is_fresh(&self, time: SystemTime) -> bool

Is the asset still valid

Source

pub fn fresh_sec(&self) -> u64

How long (in seconds) the asset should be fresh since its admission/revalidation

This is essentially the max-age value (or its equivalence). If an epoch override is set, it will be used as the reference point instead of the updated time.

Source

pub fn fresh_until(&self) -> SystemTime

Until when the asset is considered fresh

Source

pub fn age(&self) -> Duration

How old the asset is since its admission/revalidation

If an epoch override is set, it will be used as the reference point instead of the updated time.

Source

pub fn stale_while_revalidate_sec(&self) -> u32

The stale-while-revalidate limit in seconds

Source

pub fn stale_if_error_sec(&self) -> u32

The stale-if-error limit in seconds

Source

pub fn serve_stale_while_revalidate(&self, time: SystemTime) -> bool

Can the asset be used to serve stale during revalidation at the given time.

NOTE: the serve stale functions do not check !is_fresh(time), i.e. the object is already assumed to be stale.

Source

pub fn serve_stale_if_error(&self, time: SystemTime) -> bool

Can the asset be used to serve stale after error at the given time.

NOTE: the serve stale functions do not check !is_fresh(time), i.e. the object is already assumed to be stale.

Source

pub fn disable_serve_stale(&mut self)

Disable serve stale for this asset

Source

pub fn expire_at(&mut self, instant: SystemTime)

Mark this asset stale as of instant, so the next read revalidates it.

The serve stale windows are measured off fresh_until, so anchoring it on the point the asset went out of service is what keeps them the length the response asked for. A purge at P on an asset with a 10 minute stale-while-revalidate leaves the stale body servable until P + 10m, not until the asset’s own deadline plus 10 minutes. A caller that wants the next read to block on revalidation instead should call CacheMeta::disable_serve_stale as well.

instant only ever moves fresh_until earlier, so applying the same expiry on every read is safe. Passing SystemTime::now() on each read rather than the point the asset went out of service would restart the windows every time and hold them open forever. It also means an asset that has already outlived its windows keeps them closed.

Unlike CacheMeta::update_freshness this leaves updated alone, so age and provenance still describe when the asset was actually stored.

Source

pub fn update_freshness( &mut self, fresh_until: SystemTime, stale_while_revalidate_sec: u32, stale_if_error_sec: u32, )

Update the freshness metadata of this asset.

Refreshes fresh_until, stale_while_revalidate_sec, and stale_if_error_sec, and stamps updated to now. The response header, variance, epoch override, and other fields are preserved.

Source

pub fn variance(&self) -> Option<HashBinary>

Get the variance hash of this asset

Source

pub fn set_variance_key(&mut self, variance_key: HashBinary)

Set the variance key of this asset

Source

pub fn set_variance(&mut self, variance: HashBinary)

Set the variance (hash) of this asset

Source

pub fn remove_variance(&mut self)

Removes the variance (hash) of this asset

Source

pub fn response_header(&self) -> &ResponseHeader

Get the response header in this asset

Source

pub fn response_header_mut(&mut self) -> &mut ResponseHeader

Modify the header in this asset

Source

pub fn extensions(&self) -> &Extensions

Expose the extensions to read

Source

pub fn extensions_mut(&mut self) -> &mut Extensions

Expose the extensions to modify

Source

pub fn response_header_copy(&self) -> ResponseHeader

Get a copy of the response header

Source

pub fn headers(&self) -> &HMap

get all the headers of this asset

Source

pub fn serialize(&self) -> Result<(Vec<u8>, Vec<u8>)>

Serialize this object

Source

pub fn deserialize(internal: &[u8], header: &[u8]) -> Result<Self>

Deserialize from the binary format

Trait Implementations§

Source§

impl Debug for CacheMeta

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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