4 个版本

0.2.3 2023 年 4 月 29 日
0.2.2 2023 年 4 月 14 日
0.2.1 2023 年 4 月 14 日
0.2.0 2023 年 4 月 13 日
0.1.0 2023 年 4 月 12 日

#2379 in 解析器实现

每月 28 次下载

MIT 许可证

17KB
311 代码行

对象缓存

Build Version License: MIT

  • 一个简单的缓存实用程序,它可以缓存任何对象引用到内存或文件中。
  • 该crate使用SQLite数据库存储对象。
  • 它将对象转换为JSON格式并存储在给定的键下。
  • 当检索对象时发生相反的操作。

用法


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: "[email protected]".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();
}

主要功能


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) 
}

有关更详细的用法说明,请访问 GitHub 仓库

贡献

我们欢迎贡献!请参阅 贡献指南 了解更多信息。

许可证

本项目根据 MIT 许可证 的条款许可。有关详细信息,请参阅 LICENSE 文件。


[email protected]贡献者 以♥制作。

依赖关系

~33–46MB
~786K SLoC