Expand description
High-level orchestrator combining the cache, index, and rotator.
AssetManager is the entry point used by the rest of devboy-tools. It
hides the split between the physical cache directory and the in-memory
index, and enforces the rotation policy on every write.
§Concurrency and blocking
The manager wraps its mutable state in a std::sync::Mutex so it can
be freely cloned via an Arc (e.g. to be shared across tokio tasks).
The mutex serializes updates to the in-memory AssetIndex and
rotation bookkeeping: reads, writes, touches, rotation, and index
persistence all synchronize through the same critical section.
Several code paths also perform filesystem I/O while holding the lock, including:
AssetManager::get—is_file()existence check on the target file before returning the metadataAssetManager::delete—CacheManager::deleteon the target fileAssetManager::store— rotation may delete evicted files, andAssetIndex::savewritesindex.jsonatomically (temp file + rename)AssetManager::rotate_now— same rotation + persist path
The only filesystem write that intentionally runs before the lock
is acquired is the initial CacheManager::store inside
AssetManager::store, which writes the new blob to a path derived
from the caller-supplied asset_id and filename. Assuming the
caller provides unique asset_id values (which is part of the API
contract), two concurrent writes target different paths and cannot
collide. Reusing the same asset_id concurrently is unsupported and
may race on the underlying file.
Because of the above, callers must not assume these methods are free
from blocking filesystem work — if they are invoked from an async
context, wrap them in tokio::task::spawn_blocking (or equivalent)
so the executor’s worker thread isn’t stalled on disk I/O.
Structs§
- Asset
Manager - Top-level asset cache.
- Resolved
Asset - Resolved lookup result — both the cached metadata and the absolute path of the file on disk.
- Store
Request - Parameters for
AssetManager::store.