use matrix_sdk_base::{store::WellKnownResponse, ttl_cache::TtlCache};
use ruma::api::{
SupportedVersions,
client::discovery::get_authorization_server_metadata::v1::AuthorizationServerMetadata,
};
use tokio::sync::RwLock;
pub(crate) struct ClientCaches {
pub(crate) supported_versions: RwLock<CachedValue<SupportedVersions>>,
pub(super) well_known: RwLock<CachedValue<Option<WellKnownResponse>>>,
pub(crate) server_metadata: tokio::sync::Mutex<TtlCache<String, AuthorizationServerMetadata>>,
}
#[derive(Clone)]
pub(crate) enum CachedValue<Value> {
Cached(Value),
NotSet,
}
impl<Value> CachedValue<Value> {
pub(super) fn take(&mut self) -> Option<Value> {
let prev = std::mem::replace(self, Self::NotSet);
match prev {
Self::Cached(value) => Some(value),
Self::NotSet => None,
}
}
}