pub struct BadgeCache { /* private fields */ }Expand description
Badge cache with TTL support.
All badges are cached by FqdnVersion. A secondary version index tracks which
versions are cached per FQDN, enabling get_all_for_fqdn() to scan all cached
badges for a given host during rolling deployments.
Implementations§
Source§impl BadgeCache
impl BadgeCache
Sourcepub fn new(config: CacheConfig) -> Self
pub fn new(config: CacheConfig) -> Self
Create a new cache with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new cache with default configuration.
Sourcepub async fn get(&self, key: &CacheKey) -> Option<CachedBadge>
pub async fn get(&self, key: &CacheKey) -> Option<CachedBadge>
Get a cached badge by key.
Sourcepub async fn insert_with_ttl(&self, key: CacheKey, badge: Badge, ttl: Duration)
pub async fn insert_with_ttl(&self, key: CacheKey, badge: Badge, ttl: Duration)
Insert a badge with a custom soft TTL.
The soft TTL controls when CachedBadge::is_valid returns false (i.e., when
reads treat the entry as stale). The underlying moka cache still uses the
global default_ttl for hard eviction. This means entries may be filtered out
by is_valid() before moka evicts them.
Sourcepub async fn invalidate(&self, key: &CacheKey)
pub async fn invalidate(&self, key: &CacheKey)
Invalidate a cache entry.
Sourcepub fn should_refresh(&self, cached: &CachedBadge) -> bool
pub fn should_refresh(&self, cached: &CachedBadge) -> bool
Check if a cached badge should be refreshed.
Sourcepub fn entry_count(&self) -> u64
pub fn entry_count(&self) -> u64
Get the number of entries in the cache.
Sourcepub async fn get_by_fqdn_version(
&self,
fqdn: &Fqdn,
version: &Version,
) -> Option<CachedBadge>
pub async fn get_by_fqdn_version( &self, fqdn: &Fqdn, version: &Version, ) -> Option<CachedBadge>
Get a badge by FQDN and version.
Sourcepub async fn insert_for_fqdn_version(
&self,
fqdn: &Fqdn,
version: &Version,
badge: Badge,
)
pub async fn insert_for_fqdn_version( &self, fqdn: &Fqdn, version: &Version, badge: Badge, )
Insert a badge keyed by FQDN and version, updating the version index.
The version index enables get_all_for_fqdn() to discover all cached
badges for a given host.
Sourcepub async fn get_all_for_fqdn(&self, fqdn: &Fqdn) -> Vec<CachedBadge>
pub async fn get_all_for_fqdn(&self, fqdn: &Fqdn) -> Vec<CachedBadge>
Get all cached badges for an FQDN across all known versions.
Reads the version index to find which versions are cached, then fetches each one. Filters out expired entries.
Sourcepub async fn invalidate_fqdn(&self, fqdn: &Fqdn)
pub async fn invalidate_fqdn(&self, fqdn: &Fqdn)
Invalidate all cached badges for an FQDN (all versions).
Sourcepub async fn set_version_index(&self, fqdn: &Fqdn, versions: Vec<Version>)
pub async fn set_version_index(&self, fqdn: &Fqdn, versions: Vec<Version>)
Set the known versions for an FQDN from DNS records.
Called after DNS lookup to pre-populate the version index with all discovered versions, even before badges are fetched.