Store config in the cache
mufeedvh opened this issue · 1 comments
mufeedvh commented
Currently, the configuration file is saved as an environment variable instead of reading the file on every request so as to improve performance but how about storing that in cache? We need more speed! ⚡🔥
I am gonna implement this but I am kinda busy at the moment so if you want to do this, I would really appreciate it 🙌⬇️
You wanna do this?
Here's everything you need:
All the functions for configuration are in the config.rs
file.
Here is the function that stores the config:
Lines: L15-L22
fn save_config() -> std::io::Result<()> {
let config_file = File::open(CONFIG_FILE)?;
let mut buf_reader = BufReader::new(config_file);
let mut json_string = String::new();
buf_reader.read_to_string(&mut json_string)?;
env::set_var("JSON_CONFIG", json_string);
Ok(())
}
Here is the function that fetches the config:
Lines: L65-L72
pub fn get_config() -> serde_json::Value {
let bs_config = env::var("JSON_CONFIG").unwrap();
let json_config: serde_json::Value =
serde_json::from_str(&bs_config).expect("JSON was not well-formatted");
json_config
}
Just change these two functions to store the config in the cache and fetch it from the cache respectively! ⚡
mufeedvh commented
This feature has been implemented!
v0.2.0 Released! 🎉