Skip to content

dineshnukemars/object-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Object Cache

Build Version License: MIT

  • A simple cache util that takes any object reference and caches it in memory or in a file.
  • This crate uses Sqlite db to store objects.
  • It converts the object into JSON format and stores it for the given key.
  • The reverse happens when you retrieve the object.

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages