https://github.com/rmw-lib/file_cache
https://github.com/rmw-lib/file_cache
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rmw-lib/file_cache
- Owner: rmw-lib
- Created: 2022-07-12T04:07:46.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-25T08:44:28.000Z (almost 4 years ago)
- Last Synced: 2026-05-19T00:48:00.667Z (2 months ago)
- Language: Rust
- Size: 60.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# file_cache
cache file open handle
use example
[./examples/main.rs](./examples/main.rs)
```rust
use anyhow::Result;
use async_std::io::{prelude::SeekExt, ReadExt, SeekFrom};
use file_cache::FileCache;
async fn get(cache: &mut FileCache) -> Result<()> {
let mut path = std::env::current_exe()?;
(0..4).for_each(|_| {
path.pop();
});
let path = path.join("Cargo.toml").display().to_string();
let host = cache.get(path).await?;
let mut host = host.value();
host.seek(SeekFrom::Start(0)).await?;
let mut out = [0u8; 1024];
let n = host.read(&mut out).await?;
println!("{}", std::str::from_utf8(&out[..n])?);
dbg!(n);
Ok(())
}
#[async_std::main]
async fn main() -> Result<()> {
let mut cache = FileCache::new(2048)?;
get(&mut cache).await?;
Ok(())
}
```