add clear_cache function to JMClient
continuous-integration/drone/push Build is passing Details

This commit is contained in:
LordMZTE 2021-06-18 16:20:28 +02:00
parent 1d685eb772
commit a5629ea741
1 changed files with 13 additions and 0 deletions

View File

@ -36,6 +36,11 @@ impl JMClient {
JMClientBuilder::default()
}
/// clears the cache. all requests will be made again after this has been called.
pub async fn clear_cache(&mut self) {
self.cache.lock().await.clear();
}
async fn get_api_json<R, T, F>(
&self,
cache: &OnceCell<Arc<T>>,
@ -104,6 +109,14 @@ struct Cache {
memes: OnceCell<Arc<Vec<Meme>>>,
}
impl Cache {
fn clear(&mut self) {
self.users = OnceCell::default();
self.cats = OnceCell::default();
self.memes = OnceCell::default();
}
}
#[derive(Debug, Default)]
pub struct JMClientBuilder {
client: Option<reqwest::Client>,