pub struct PowCapabilityStore { /* private fields */ }Expand description
Capacity-bounded LRU+TTL store of
PowCapabilityProfiles.
Reuses the same LruTtlStore
primitive the T83 ChallengeMemory
and the T91 NonceBook
use. That keeps eviction + expiry semantics consistent
across all three short-horizon stores and satisfies the
“no new cache store” constraint.
§Example
use stygian_charon::pow_profile::{PowCapabilitySample, PowCapabilityStore};
use stygian_charon::types::TargetClass;
use stygian_charon::vendor_classifier::VendorId;
let store = PowCapabilityStore::with_defaults();
store.record_sample(
"example.com",
TargetClass::ContentSite,
VendorId::Cloudflare,
&PowCapabilitySample::solved(1_000, 0),
);
let profile = store
.lookup("example.com", TargetClass::ContentSite, VendorId::Cloudflare)
.expect("profile");
assert_eq!(profile.solved_count, 1);Implementations§
Source§impl PowCapabilityStore
impl PowCapabilityStore
Sourcepub fn new(capacity: NonZeroUsize, ttl: Duration) -> Self
pub fn new(capacity: NonZeroUsize, ttl: Duration) -> Self
Create a new store with explicit capacity and TTL.
Sourcepub fn with_default_ttl(capacity: NonZeroUsize) -> Self
pub fn with_default_ttl(capacity: NonZeroUsize) -> Self
Capacity-bounded PowCapabilityStore with
DEFAULT_POW_TTL.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Capacity-bounded PowCapabilityStore with
DEFAULT_POW_CAPACITY and DEFAULT_POW_TTL.
Sourcepub fn record_sample(
&self,
domain: &str,
target_class: TargetClass,
vendor: VendorId,
sample: &PowCapabilitySample,
)
pub fn record_sample( &self, domain: &str, target_class: TargetClass, vendor: VendorId, sample: &PowCapabilitySample, )
Record a PowCapabilitySample for a
(domain, target_class, vendor) triple. The store
looks up the existing profile (if any), merges the
sample into it, and re-inserts the updated profile
under the LRU+TTL semantics shared with
LruTtlStore.
The LRU recency is not bumped on the read so a high-volume key does not crowd out less common keys (matches the T83 / T91 pattern).
Sourcepub fn lookup(
&self,
domain: &str,
target_class: TargetClass,
vendor: VendorId,
) -> Option<PowCapabilityProfile>
pub fn lookup( &self, domain: &str, target_class: TargetClass, vendor: VendorId, ) -> Option<PowCapabilityProfile>
Look up the current profile for a
(domain, target_class, vendor) triple. Returns
None if the key is absent or has expired.
Sourcepub fn invalidate(
&self,
domain: &str,
target_class: TargetClass,
vendor: VendorId,
)
pub fn invalidate( &self, domain: &str, target_class: TargetClass, vendor: VendorId, )
Invalidate a single (domain, target_class, vendor)
key.