Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/fuels-accounts/src/provider/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ trait Clock {
#[derive(Debug, Clone)]
pub struct TtlConfig {
pub consensus_parameters: Duration,
pub node_info: Duration,
}

impl Default for TtlConfig {
fn default() -> Self {
TtlConfig {
consensus_parameters: Duration::from_secs(60),
node_info: Duration::from_secs(60),
}
}
}
Expand Down Expand Up @@ -90,6 +92,7 @@ where
{
pub async fn clear(&self) {
*self.cached_consensus_params.write().await = None;
*self.cached_node_info.write().await = None;
}
}

Expand Down Expand Up @@ -128,8 +131,7 @@ where
}

async fn node_info(&self) -> Result<NodeInfo> {
// must borrow from consensus_parameters to keep the change non-breaking
let ttl = self.ttl_config.consensus_parameters;
let ttl = self.ttl_config.node_info;
{
let read_lock = self.cached_node_info.read().await;
if let Some(entry) = read_lock.as_ref()
Expand Down Expand Up @@ -214,6 +216,7 @@ mod tests {
api,
TtlConfig {
consensus_parameters: Duration::from_secs(10),
node_info: Duration::from_secs(10),
},
TestClock::default(),
);
Expand Down Expand Up @@ -259,6 +262,7 @@ mod tests {
api,
TtlConfig {
consensus_parameters: Duration::from_secs(10),
node_info: Duration::from_secs(10),
},
clock.clone(),
);
Expand Down Expand Up @@ -362,6 +366,7 @@ mod tests {
api,
TtlConfig {
consensus_parameters: Duration::from_secs(10),
node_info: Duration::from_secs(10),
},
TestClock::default(),
);
Expand Down Expand Up @@ -405,6 +410,7 @@ mod tests {
api,
TtlConfig {
consensus_parameters: Duration::from_secs(10),
node_info: Duration::from_secs(10),
},
clock.clone(),
);
Expand Down