add clear_cache function to JMClient
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1d685eb772
commit
a5629ea741
1 changed files with 13 additions and 0 deletions
|
@ -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>,
|
||||
|
|
Loading…
Reference in a new issue