pub(crate) enum CacheState {
Fresh(String),
Stale(String),
Miss,
}
pub(crate) trait CachePort {
fn check(&self, repo_id: &str) -> CacheState;
}
pub(crate) enum DisplayAction {
Display(String),
DisplayAndRefresh(String),
LoadingWithRefresh,
}
pub(crate) fn resolve(repo_id: &str, cache: &impl CachePort) -> DisplayAction {
match cache.check(repo_id) {
CacheState::Fresh(s) => DisplayAction::Display(s),
CacheState::Stale(s) => DisplayAction::DisplayAndRefresh(s),
CacheState::Miss => DisplayAction::LoadingWithRefresh,
}
}