pub struct ReleaseDatesCache { /* private fields */ }Expand description
Memoized, best-effort GitHub Releases publish-date cache.
Shared by every ecosystem that resolves package versions from GitHub tags but wants to
enrich them with a release’s published_at (deps-swift, deps-github-actions).
Fetching /releases is a second, separate request from the tags fetch that produces
the version list itself — Self::fetch is meant to run concurrently with that tags
fetch (e.g. via tokio::join!) and is infallible by construction, so it can never
perturb the tags fetch’s error propagation. A caller joins the returned map onto its own
already-fetched, ecosystem-specific version list by normalize_taging each version’s
tag text (#223).
One cache may safely be shared across Self::fetch calls passing different
GithubTagsClients (e.g. a caller that swaps in a mock client under test): entries are
keyed on (client.api_base(), name), not name alone, so a hit fetched via one origin’s
client can never serve a read for another origin (#486 critic M1).
Implementations§
Source§impl ReleaseDatesCache
impl ReleaseDatesCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty cache.
§Examples
use deps_core::github::ReleaseDatesCache;
let _cache = ReleaseDatesCache::new();Sourcepub async fn fetch(
&self,
github: &GithubTagsClient,
name: &str,
ecosystem: &'static str,
) -> Arc<HashMap<String, PublishTime>>
pub async fn fetch( &self, github: &GithubTagsClient, name: &str, ecosystem: &'static str, ) -> Arc<HashMap<String, PublishTime>>
Fetches the newest ~100 GitHub Releases for name (owner/repo) via github, and
returns a normalized-tag -> publish-time map, memoized behind a per-package TTL.
Best-effort by construction (#223): a malformed identity or a validation failure
returns an empty map with zero requests; a missing GITHUB_TOKEN returns an
empty map (logged once per cache instance, naming ecosystem) with zero requests; any
live-fetch error (network, rate limit, unparseable body, or exceeding the fetch
timeout) returns an empty map, memoized under the short error TTL rather than the
positive success TTL. Never propagates an error — a caller running this under
tokio::join! alongside a tags fetch must not have that fetch perturbed by a
release-dates failure.
Runs its own validate_owner_repo guard, independent of any validation the tags
fetch performs: under a tokio::join! that guard may not run first, and this method
interpolates name into an api.github.com path of its own (#223 M6).
§Examples
A malformed identity is rejected before any request is built — deterministic and network-free, so it doubles as a runnable example:
use deps_core::HttpCache;
use deps_core::github::{GithubTagsClient, ReleaseDatesCache};
use std::sync::Arc;
let cache = ReleaseDatesCache::new();
let github = GithubTagsClient::new(Arc::new(HttpCache::new()));
let dates = cache.fetch(&github, "not-a-valid-owner-repo", "Example").await;
assert!(dates.is_empty());