Crates.io | rom_cache |
lib.rs | rom_cache |
version | |
source | src |
created_at | 2024-07-26 23:36:20.449316 |
updated_at | 2024-10-19 21:52:50.922441 |
description | A rust crate to cache ROM in memory like CPU caching RAM. |
homepage | |
repository | https://github.com/kingwingfly/rom-cache |
max_upload_size | |
id | 1316883 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A rust crate to cache ROM in RAM like CPU caches RAM.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
[dependencies]
rom_cache = { version = "0.0.12" }
A rust crate to cache ROM in memory like CPU caching RAM.
Trait Cacheable
is provided to enable user define how to load
and store
data in Secondary Storage.
Cache
is the main entry of this crate, which consists of CacheGroup
s. And CacheGroup
consists of CacheLine
s.
Cache::get::<T>()
and Cache::get_mut::<T>()
are provided to retrieve data from Cache and storage. LRU is used to choose the CacheLine
for T
.
CacheRef
CacheError::Busy
, LRU-chosen CacheLine
is still being writting or reading so that unable to be evicted.CacheError::Locked
, cannot read T
while writing.CacheMut
, and dereferencing CacheMut
will set CacheLine
dirty.CacheError::Busy
, cannot evict LRU-chosen CacheLine
which is still being used.CacheError::Locked
, cannot write T
while reading or writing.Any dirty CacheLine
will be written back (Cacheable::store()
) to Secondary Storage when evicted or Cache
dropped.
nightly
: enable #![feature(trait_upcasting)]
to simplify the Cacheable
trait. (Nightly Rust is needed)# use rom_cache::Cache;
// e.g 2-way set associative cache (8 sets/groups), 16 cache lines in total
let cache: Cache<8, 2> = Default::default();
cache.get::<isize>().unwrap();
cache.get::<String>().unwrap();
{
let mut s = cache.get_mut::<String>().unwrap();
cache.get::<u64>().unwrap();
cache.get::<usize>().unwrap();
*s = "".to_string(); // set dirty
}
{
let s = cache.get::<String>().unwrap(); // other threads may evict `String` and it's stored,
// this will load it back
assert_eq!(*s, ""); // The `load` result is `""`
}
For more examples, please refer to the Tests, Example or Documentation
todo
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE.txt
for more information.
Louis - 836250617@qq.com
Project Link: https://github.com/kingwingfly/rom-cache