MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / prune_old_cache_entries

Function prune_old_cache_entries

rust/src/lib.rs:1809–1835  ·  view source on GitHub ↗

Removes cached driver and browser binaries whose `last_used` timestamp (tracked in the `cached_assets` section of the metadata) is older than `ttl_days` days. `cached_assets` is intentionally separate from the TTL-based `drivers`/`browsers` entries so that usage history survives beyond the short version-discovery TTL (default: 1 hour). This prevents binaries from escaping pruning just because the

(log: &Logger, cache_path: &str, ttl_days: u64)

Source from the content-addressed store, hash-verified

1807/// This prevents binaries from escaping pruning just because their metadata entry was already
1808/// flushed by a routine write for a different driver or browser.
1809pub fn prune_old_cache_entries(log: &Logger, cache_path: &str, ttl_days: u64) {
1810 let cache = Path::new(cache_path);
1811 if !cache.exists() {
1812 return;
1813 }
1814 let cache_path_buf = cache.to_path_buf();
1815 let mut metadata = get_metadata(log, &Some(cache_path_buf.clone()));
1816 let cutoff = now_unix_timestamp().saturating_sub(ttl_days * 24 * 3600);
1817
1818 let old_assets: Vec<(String, String)> = metadata
1819 .cached_assets
1820 .iter()
1821 .filter(|a| a.last_used < cutoff)
1822 .map(|a| (a.asset_name.clone(), a.asset_version.clone()))
1823 .collect();
1824
1825 if old_assets.is_empty() {
1826 return;
1827 }
1828
1829 for (name, version) in &old_assets {
1830 delete_cached_asset(log, cache, name, version);
1831 }
1832
1833 metadata.cached_assets.retain(|a| a.last_used >= cutoff);
1834 write_metadata(&metadata, log, Some(cache_path_buf));
1835}
1836
1837fn delete_cached_asset(log: &Logger, cache: &Path, asset_name: &str, asset_version: &str) {
1838 let asset_dir = cache.join(asset_name);

Calls 9

get_metadataFunction · 0.85
now_unix_timestampFunction · 0.85
delete_cached_assetFunction · 0.85
write_metadataFunction · 0.85
existsMethod · 0.80
collectMethod · 0.80
filterMethod · 0.80
is_emptyMethod · 0.80
mapMethod · 0.45