pub struct WasmCache { /* private fields */ }Expand description
A local file-system cache for Soroban WASM metadata and binaries.
Implementations§
Source§impl WasmCache
impl WasmCache
Sourcepub fn new() -> Result<Self, StorageError>
pub fn new() -> Result<Self, StorageError>
Creates a new WasmCache instance.
The directory location can be overridden via the SDKT_CACHE_DIR environment
variable (checked first). If unset or empty, uses the standard OS cache directory:
- Linux:
~/.cache/soroban-devkit/ - macOS:
~/Library/Caches/org.SaboLabs.soroban-devkit/ - Windows:
%LOCALAPPDATA%\SaboLabs\soroban-devkit\cache\
Sourcepub fn with_dir<P: AsRef<Path>>(path: P) -> Self
pub fn with_dir<P: AsRef<Path>>(path: P) -> Self
Creates a cache instance targeting a specific directory (useful for testing).
Sourcepub fn contains(
&self,
network: &str,
wasm_hash: &str,
) -> Result<bool, StorageError>
pub fn contains( &self, network: &str, wasm_hash: &str, ) -> Result<bool, StorageError>
Returns true if metadata for the wasm_hash exists in the given network.
Sourcepub fn get(
&self,
network: &str,
wasm_hash: &str,
) -> Result<Option<WasmMetadata>, StorageError>
pub fn get( &self, network: &str, wasm_hash: &str, ) -> Result<Option<WasmMetadata>, StorageError>
Retrieves parsed metadata from the cache.
§Errors
Returns StorageError::CorruptCache if the JSON is malformed.
Sourcepub fn put(
&self,
network: &str,
metadata: &WasmMetadata,
wasm_bytes: &[u8],
) -> Result<(), StorageError>
pub fn put( &self, network: &str, metadata: &WasmMetadata, wasm_bytes: &[u8], ) -> Result<(), StorageError>
Writes both metadata and raw WASM to the cache using atomic tempfile renaming.
Sourcepub fn remove(&self, network: &str, wasm_hash: &str) -> Result<(), StorageError>
pub fn remove(&self, network: &str, wasm_hash: &str) -> Result<(), StorageError>
Removes a specific WASM entry (both JSON and .wasm) from the cache.
A hash that is not cached is an error, not a silent success: callers
print “Removed” on Ok, and reporting success for a no-op reads as a
completed mutation to scripts and agents. Matches identity delete and
network remove, which surface Not found: and exit non-zero.
Sourcepub fn clear(&self, network: &str) -> Result<(), StorageError>
pub fn clear(&self, network: &str) -> Result<(), StorageError>
Clears all cached WASM entries for a specific network.
Unlike remove, this stays truthful as a no-op success: “cleared” is
accurate for an empty cache (the post-condition holds), and unlike a
hash miss it is not evidence that a named target was deleted.
Sourcepub fn cache_info(&self, network: &str) -> Result<CacheInfo, StorageError>
pub fn cache_info(&self, network: &str) -> Result<CacheInfo, StorageError>
Retrieves usage statistics for a specific network.
A missing or unreadable cache directory is treated as an empty cache
(zero entries / zero size) on every platform. This keeps cache info
working on fresh CI runners (Linux/macOS/Windows) where the cache path
does not yet exist.