Expand description
A simple file-based cache for storing data on disk temporarily.
Ported from internal/filecache/filecache.go, interface.go,
noop.go, and singlegroup.go.
Go’s SingleGroup[T any] wraps golang.org/x/sync/singleflight,
collapsing concurrent calls for the same key into one execution. The
idiomatic Rust equivalent is tokio::sync::OnceCell-per-key or a
dashmap-backed in-flight map with tokio::sync::Notify; this crate
doesn’t pull in either dependency since nothing ported here needs
cross-call coalescing yet (each Cache call is independent). See
PORT_NOTES.md.
Structs§
- File
Cache - Ported from the unexported
fileCachestruct.
Enums§
- File
Cache Error - Ported from
ErrInvalidMaxAge/ErrFallbackFailed.
Traits§
- Cache
- Ported from the
Cacheinterface.
Functions§
- new
- Ported from
New. Derives the cache path fromnameand the OS user cache directory (dirs::cache_dir(), the Rust-idiomatic equivalent of Go’sos.UserCacheDir():$XDG_CACHE_HOME/~/.cacheon Linux,~/Library/Cacheson macOS), then delegates tonew_at. There is no Go test for this path directly (filecache_test.goonly tests the zero-maxAgerejection here; everything else goes throughnew_at), matching the same “ambient OS state has no test to port against” situation asdatadir::dir_in’s caller-resolves-$HOMEdesign – this is simple enough, and specified precisely enough by the Go source, not to need one invented. - new_at
- Ported from
NewAt. - noop
- Ported from
Noopinnoop.go, with the base temp directory taken as an explicit parameter (noop_in) rather than read from$TMPDIR/os.TempDir()internally, for the same reason asdatadir::dir_in: Go’s test isolates this witht.Setenv("TMPDIR", ...), which has no safe equivalent under Rust’s default multi-threaded test runner.noop()is the zero-argument production entry point. - noop_in
- See
noop’s doc comment for whybase_diris explicit here.
Type Aliases§
- Fallback
- Ported from the
Fallbackfunction type. Go’s version takes acontext.Context; this port’s fallback signature omits it for now (seecrate::exec::context’s discussion of ambient context) and will need revisiting once cancellation is threaded through in Phase 4.