rom_cache 0.0.1-alpha2

A rust crate to cache ROM in memory like CPU caching RAM.
Documentation

Contributors Forks Stargazers Issues MIT License

Import

[dependencies]
rom_cache = { version = "0.0.1-alpha2" }

About The Project

A rust crate to cache ROM in memory like CPU caching RAM.

Trait Cacheable is provided to let user define how to load and store data in Secondary Storage.

  1. get (RwLockReadGuard)
  • cache hit: return CacheRef from cache.
  • cache miss: CacheError::Miss.
  1. get mut (RwLockWriteGuard)
  • cache hit: return CacheMut from cache, and dereferring CacheMut sets CacheLine dirty.
  • cache miss: CacheError::Miss
  1. load
  • cache hit: upgrade LRU.
  • cache miss and find empty line: load data from Secondary Storage (Cacheable::load()).
  • cache miss and no empty line: LRU algorithm to evict data.

Any dirty CacheLine will be written back (Cacheable::store()) to Secondary Storage when evicted.

feature

  • nightly: enable #![feature(trait_upcasting)]

Built With

  • Rust
  • Miri (Testing)

Usage

Example

# use rom_cache::Cache;
// e.g 2-way set associative cache (8 sets)
let mut cache: Cache<8, 2> = Default::default();
cache.load::<String>().unwrap();
{
    let mut s = cache.get_mut::<String>().unwrap();
    *s = "hello, world.".to_string();
}
{
    let s = cache.get::<String>().unwrap();
    assert_eq!(*s, "hello, world.");
}
cache.load::<i32>().unwrap();
cache.load::<i64>().unwrap();
cache.load::<isize>().unwrap();
{
    let mut n = cache.get_mut::<isize>().unwrap();
    *n = 42;
}
cache.load::<u32>().unwrap();
cache.load::<u64>().unwrap();
cache.load::<usize>().unwrap();
{
    let n = cache.get::<usize>().unwrap();
    assert_eq!(*n, 0);
}

For more examples, please refer to the Tests, Example or Documentation

Changelog

todo

more detailed changelog

Roadmap

  • allow concurrent access
  • auto load when cache miss

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Louis - 836250617@qq.com

Project Link: https://github.com/kingwingfly/rom-cache