Skip to content

Commit

Permalink
make the ttl for the storage mapping of the root storage much higher
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Feb 7, 2025
1 parent f791ad1 commit 187c087
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/storage_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ struct CachedAccess {
impl CachedAccess {
pub fn new(access: Vec<UserStorageAccess>) -> Self {
let mut rng = thread_rng();
Self::with_ttl(
access,
Duration::from_millis(rng.gen_range((4 * 60 * 1000)..(5 * 60 * 1000))),
);
}
pub fn with_ttl(access: Vec<UserStorageAccess>, ttl: Duration) -> Self {
Self {
access,
valid_till: Instant::now()
+ Duration::from_millis(rng.gen_range((4 * 60 * 1000)..(5 * 60 * 1000))),
valid_till: Instant::now() + ttl,
}
}

Expand Down Expand Up @@ -76,7 +81,14 @@ impl StorageMapping {
} else {
let users = self.load_storage_mapping(storage).await?;

self.cache.insert(storage, CachedAccess::new(users));
self.cache.insert(
storage,
if storage == 1 {
CachedAccess::with_ttl(users, Duration::from_secs(24 * 60 * 60))
} else {
CachedAccess::new(users)
},
);
Ok(self.cache.get(&storage).unwrap())
}
}
Expand Down

0 comments on commit 187c087

Please sign in to comment.