object-cache

Crates.ioobject-cache
lib.rsobject-cache
version0.2.3
sourcesrc
created_at2023-04-12 02:30:53.577806
updated_at2023-04-29 17:11:28.147191
descriptionsave or get object from file cache
homepage
repository
max_upload_size
id836508
size18,058
sky (dineshnukemars)

documentation

README

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.

Commit count: 0

cargo fmt