pub struct CacheMeta(/* private fields */);Expand description
The cacheable response header and cache metadata
Implementations§
Source§impl CacheMeta
impl CacheMeta
Sourcepub fn new(
fresh_until: SystemTime,
created: SystemTime,
stale_while_revalidate_sec: u32,
stale_if_error_sec: u32,
header: ResponseHeader,
) -> CacheMeta
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
Sourcepub fn created(&self) -> SystemTime
pub fn created(&self) -> SystemTime
When the asset was created/admitted to cache
Sourcepub fn updated(&self) -> SystemTime
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
Sourcepub fn provenance(&self) -> SystemTime
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.
Sourcepub fn epoch(&self) -> SystemTime
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.
Sourcepub fn epoch_override(&self) -> Option<SystemTime>
pub fn epoch_override(&self) -> Option<SystemTime>
Get the epoch override for this asset
Sourcepub fn set_epoch_override(&mut self, epoch: SystemTime)
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.
Sourcepub fn remove_epoch_override(&mut self)
pub fn remove_epoch_override(&mut self)
Remove the epoch override for this asset
Sourcepub fn is_fresh(&self, time: SystemTime) -> bool
pub fn is_fresh(&self, time: SystemTime) -> bool
Is the asset still valid
Sourcepub fn fresh_sec(&self) -> u64
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.
Sourcepub fn fresh_until(&self) -> SystemTime
pub fn fresh_until(&self) -> SystemTime
Until when the asset is considered fresh
Sourcepub fn age(&self) -> Duration
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.
Sourcepub fn stale_while_revalidate_sec(&self) -> u32
pub fn stale_while_revalidate_sec(&self) -> u32
The stale-while-revalidate limit in seconds
Sourcepub fn stale_if_error_sec(&self) -> u32
pub fn stale_if_error_sec(&self) -> u32
The stale-if-error limit in seconds
Sourcepub fn serve_stale_while_revalidate(&self, time: SystemTime) -> bool
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.
Sourcepub fn serve_stale_if_error(&self, time: SystemTime) -> bool
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.
Sourcepub fn disable_serve_stale(&mut self)
pub fn disable_serve_stale(&mut self)
Disable serve stale for this asset
Sourcepub fn expire_at(&mut self, instant: SystemTime)
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.
Sourcepub fn update_freshness(
&mut self,
fresh_until: SystemTime,
stale_while_revalidate_sec: u32,
stale_if_error_sec: u32,
)
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.
Sourcepub fn variance(&self) -> Option<HashBinary>
pub fn variance(&self) -> Option<HashBinary>
Get the variance hash of this asset
Sourcepub fn set_variance_key(&mut self, variance_key: HashBinary)
pub fn set_variance_key(&mut self, variance_key: HashBinary)
Set the variance key of this asset
Sourcepub fn set_variance(&mut self, variance: HashBinary)
pub fn set_variance(&mut self, variance: HashBinary)
Set the variance (hash) of this asset
Sourcepub fn remove_variance(&mut self)
pub fn remove_variance(&mut self)
Removes the variance (hash) of this asset
Sourcepub fn response_header(&self) -> &ResponseHeader
pub fn response_header(&self) -> &ResponseHeader
Get the response header in this asset
Sourcepub fn response_header_mut(&mut self) -> &mut ResponseHeader
pub fn response_header_mut(&mut self) -> &mut ResponseHeader
Modify the header in this asset
Sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Expose the extensions to read
Sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Expose the extensions to modify
Sourcepub fn response_header_copy(&self) -> ResponseHeader
pub fn response_header_copy(&self) -> ResponseHeader
Get a copy of the response header
Sourcepub fn deserialize(internal: &[u8], header: &[u8]) -> Result<Self>
pub fn deserialize(internal: &[u8], header: &[u8]) -> Result<Self>
Deserialize from the binary format