Skip to main content

Module filecache

Module filecache 

Source
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§

FileCache
Ported from the unexported fileCache struct.

Enums§

FileCacheError
Ported from ErrInvalidMaxAge/ErrFallbackFailed.

Traits§

Cache
Ported from the Cache interface.

Functions§

new
Ported from New. Derives the cache path from name and the OS user cache directory (dirs::cache_dir(), the Rust-idiomatic equivalent of Go’s os.UserCacheDir(): $XDG_CACHE_HOME/~/.cache on Linux, ~/Library/Caches on macOS), then delegates to new_at. There is no Go test for this path directly (filecache_test.go only tests the zero-maxAge rejection here; everything else goes through new_at), matching the same “ambient OS state has no test to port against” situation as datadir::dir_in’s caller-resolves-$HOME design – 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 Noop in noop.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 as datadir::dir_in: Go’s test isolates this with t.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 why base_dir is explicit here.

Type Aliases§

Fallback
Ported from the Fallback function type. Go’s version takes a context.Context; this port’s fallback signature omits it for now (see crate::exec::context’s discussion of ambient context) and will need revisiting once cancellation is threaded through in Phase 4.