I'm writing a cache manager for my HTTP proxy. I want it to write downloaded data to the disk first before serving data to the client. So there are two cases, while still downloading, the downloading task holds a tokio::fs::File to the cache data, and when completed, a new File has to be created to read the data.
I haven't dealt with file I/O much and I wonder if I can just write a function like async fn load_data(start: u64, end:u64)-> Result<Vec, anyhow::Error> which opens the cache file every time it gets called, even if it's already opened somewhere else. Otherwise I'll need to write two similar functions, only that one will need to take a mutable File reference then seek positions back and forth.