add clear_cache function to JMClient
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
LordMZTE 2021-06-18 16:20:28 +02:00
parent 1d685eb772
commit a5629ea741

View file

@ -36,6 +36,11 @@ impl JMClient {
JMClientBuilder::default() 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>( async fn get_api_json<R, T, F>(
&self, &self,
cache: &OnceCell<Arc<T>>, cache: &OnceCell<Arc<T>>,
@ -104,6 +109,14 @@ struct Cache {
memes: OnceCell<Arc<Vec<Meme>>>, 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)] #[derive(Debug, Default)]
pub struct JMClientBuilder { pub struct JMClientBuilder {
client: Option<reqwest::Client>, client: Option<reqwest::Client>,