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

Function prune_old_cache_entries

rust/src/lib.rs:1757–1783  ·  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

1755/// This prevents binaries from escaping pruning just because their metadata entry was already
1756/// flushed by a routine write for a different driver or browser.
1757pub fn prune_old_cache_entries(log: &Logger, cache_path: &str, ttl_days: u64) {
1758 let cache = Path::new(cache_path);
1759 if !cache.exists() {
1760 return;
1761 }
1762 let cache_path_buf = cache.to_path_buf();
1763 let mut metadata = get_metadata(log, &Some(cache_path_buf.clone()));
1764 let cutoff = now_unix_timestamp().saturating_sub(ttl_days * 24 * 3600);
1765
1766 let old_assets: Vec<(String, String)> = metadata
1767 .cached_assets
1768 .iter()
1769 .filter(|a| a.last_used < cutoff)
1770 .map(|a| (a.asset_name.clone(), a.asset_version.clone()))
1771 .collect();
1772
1773 if old_assets.is_empty() {
1774 return;
1775 }
1776
1777 for (name, version) in &old_assets {
1778 delete_cached_asset(log, cache, name, version);
1779 }
1780
1781 metadata.cached_assets.retain(|a| a.last_used >= cutoff);
1782 write_metadata(&metadata, log, Some(cache_path_buf));
1783}
1784
1785fn delete_cached_asset(log: &Logger, cache: &Path, asset_name: &str, asset_version: &str) {
1786 let asset_dir = cache.join(asset_name);

Calls 8

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