Object Cache

Build Version License: MIT

Usage


async fn sample(){
    // build Cache with name (Could be In memory or File based cache)
    let cache = Cache::build(true, "obj_cache").await;

    let data = TestStruct {
        name: "dinesh".to_owned(),
        email: "dinesh.nuke.mars@gmail.com".to_owned(),
        ph_no: 9999999999u64,
    };

    // pass key and object
    cache.save_obj("TestData", &data).await.unwrap();

    // visualize the data
    cache.pretty_print_all_cache();

    // get object anywhere in the project using key
    let cached_data: TestStruct = cache.get_obj("TestData").await.unwrap();
}

Main Functions


Cache {
    pub async fn build(in_memory: bool, cache_file_name: &str) -> Self 
    pub async fn save_obj<T>(&self, key: &str, obj: &T) -> Result<(), CacheError
    pub async fn save_obj_if_not_exist<T>(&self, key: &str, obj: &T) -> Result<(), CacheError
    pub async fn get_obj<T>(&self, key: &str) -> Result<T, CacheError
    pub async fn get_all_objs(&self) -> Result<Vec<CacheData>, CacheError> 
    pub async fn pretty_print_all_cache(&self) 
    pub async fn clear_cache(&self) 
}

For more detailed usage instructions, visit the GitHub repository.

Contributing

We welcome contributions! Please see the contributing guidelines for more information.

License

This project is licensed under the terms of the MIT License. See the LICENSE file for more details.


Made with ♥ by dinesh.nuke.mars@gmail.comand contributors.