1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! # Shared types and tuning constants for the bundle caches
//!
//! The common pieces used by both
//! [`crate::server::post_bundle_caching`] and
//! [`crate::server::post_bundle_feedback_caching`]:
//!
//! - [`CachedBundle`] — bytes + optional `expires_at`. *Live* (still-mutating)
//! bundles carry an expiry; *sealed* (immutable past-tense) bundles do not and stay
//! cached until evicted by LRU pressure.
//! - [`GetCacheResult`] — lookup outcome: `Miss`, `Hit`, `HitAndIssueToken` (the
//! latter triggering [`hashiverse_lib::protocol::payload::payload::CacheRequestTokenV1`]
//! emission from the caller).
//! - `CACHE_LOCATION_TTI` (60 s) and `CACHE_HIT_THRESHOLD` (10) — the tuning that
//! decides when a bundle is "hot enough" to justify asking callers to help replicate
//! it further.
use Bytes;
use CacheRequestTokenV1;
use ;
use Duration;
/// TTI for all cache entries: if a location_id hasn't been queried for a while, evict it entirely.
pub const CACHE_LOCATION_TTI: Duration = from_secs;
/// Number of hits on a placeholder entry before the server issues a CacheRequestToken.
/// Essentially: have we had this many requests in the last `CACHE_LOCATION_TTI`? If so, start caching.
pub const CACHE_HIT_THRESHOLD: u32 = 10;
/// How long a CacheRequestToken is valid for (client must upload within this window).
pub const CACHE_REQUEST_TOKEN_TTL_DURATION_MILLIS: DurationMillis = MILLIS_IN_SECOND.const_mul;
pub const CACHE_REQUEST_TOKEN_TTL_DURATION: Duration = from_millis;
/// One bundle (from one originator peer) held in the cache.
/// Result returned to the dispatch handler by either cache's `on_get`.