is_offline
Stable function · Cache
Tier: stable · Kind: function · Topic: Cache
| Python | Julia | Rust |
|---|---|---|
resolve_offline | is_offline | is_offline |
Python
resolve_offline(explicit: Optional[bool] = None) -> bool
Resolve effective offline mode.
explicit of True/False wins; None means “consult the
environment” (EARTHSCI_OFFLINE). This sentinel is how the spec’s “the
explicit argument wins over the environment when both are present” is honored
without conflating an unset argument with an explicit False.
Example (offline)
offline = Cache(root=cache_root, offline=True)
assert offline.fetch(URL).path == entry.path # served from disk only
try:
offline.fetch((FIXTURES / "not-cached.csv").as_uri())
raise AssertionError("an offline miss must raise")
except CacheMiss:
pass # offline mode never touches the network
Julia
is_offline(c::Cache)
True if this cache is in offline (cache-only) mode.
Example (offline)
offline = Cache(; root = CACHE_ROOT, offline = true)
@assert is_offline(offline)
@assert fetch_blob(offline, URL).path == entry.path # served from disk only
missed = try
fetch_blob(offline, "file://" * abspath(joinpath(FIXTURES, "not-cached.csv")))
false
catch err
err isa CacheMiss # offline mode never touches the network
end
@assert missed
Rust
pub fn is_offline(explicit: Option<bool>) -> bool
Resolve the effective offline flag: the explicit argument wins; otherwise
fall back to EARTHSCI_OFFLINE.
Example (offline)
let offline = Cache::builder()
.data_dir(cache_root.path())
.offline(true)
.build()?;
assert!(offline.is_offline());
assert_eq!(offline.fetch(&FetchRequest::new(&url))?.path, blob.path); // served from disk only
// An offline miss is an error, never a network request.
let miss = offline
.fetch(&FetchRequest::new("file:///not/cached.csv"))
.unwrap_err();
assert!(miss.is_cache_miss());