Refresh keys if the TTL has elapsed. Holds the refresh mutex so concurrent callers coalesce into a single HTTP fetch. The second caller will re-check the TTL after acquiring the lock and find it fresh.
(&self)
| 262 | /// HTTP fetch. The second caller will re-check the TTL after acquiring |
| 263 | /// the lock and find it fresh. |
| 264 | async fn refresh_if_stale(&self) -> Result<(), String> { |
| 265 | let last = *self.last_refresh.read().await; |
| 266 | if last.elapsed() <= self.ttl { |
| 267 | return Ok(()); |
| 268 | } |
| 269 | let _guard = self.refresh_mutex.lock().await; |
| 270 | // Re-check after acquiring the lock — another task may have refreshed. |
| 271 | let last = *self.last_refresh.read().await; |
| 272 | if last.elapsed() <= self.ttl { |
| 273 | return Ok(()); |
| 274 | } |
| 275 | self.refresh_keys().await |
| 276 | } |
| 277 | |
| 278 | /// Refresh keys unconditionally, coalescing concurrent callers. |
| 279 | async fn refresh_keys_coalesced(&self) -> Result<(), String> { |
no test coverage detected