Expand description
§GitHub Actions cache client
The CacheClient is an idiomatic Rust port of
@actions/cache.
See Caching dependencies to speed up workflows for the official GitHub documentation.
use std::io::Cursor;
use std::time::SystemTime;
let version = SystemTime::UNIX_EPOCH.elapsed()?.as_millis();
let cache_key = format!("gha-toolkit-{version:#x}");
let client = CacheClient::from_env()?
.cache_from([&cache_key].into_iter())
.cache_to(&cache_key)
.build()?;
let scope = "gha_toolkit::cache";
let data = "Hello World!";
// Create a new cache entry.
client.put(scope, Cursor::new(data)).await?;
// Read from the cache entry.
let cache_entry = client.entry(scope).await?.expect("cache entry");
// Fetch the cache data.
let archive_location = cache_entry.archive_location.expect("archive location");
let cached_bytes = client.get(&archive_location).await?;
// Decode the cache data to a UTF-8 string.
let cached_data = String::from_utf8(cached_bytes)?;
assert_eq!(cached_data, data);Structs§
- Artifact
Cache Entry - GitHub Actions cache entry.
- Cache
Client - GitHub Actions cache client.
- Cache
Client Builder - GitHub Actions cache client builder.