File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,15 @@ struct CachedAccess {
3232impl CachedAccess {
3333 pub fn new ( access : Vec < UserStorageAccess > ) -> Self {
3434 let mut rng = thread_rng ( ) ;
35+ Self :: with_ttl (
36+ access,
37+ Duration :: from_millis ( rng. gen_range ( ( 4 * 60 * 1000 ) ..( 5 * 60 * 1000 ) ) ) ,
38+ )
39+ }
40+ pub fn with_ttl ( access : Vec < UserStorageAccess > , ttl : Duration ) -> Self {
3541 Self {
3642 access,
37- valid_till : Instant :: now ( )
38- + Duration :: from_millis ( rng. gen_range ( ( 4 * 60 * 1000 ) ..( 5 * 60 * 1000 ) ) ) ,
43+ valid_till : Instant :: now ( ) + ttl,
3944 }
4045 }
4146
@@ -76,7 +81,14 @@ impl StorageMapping {
7681 } else {
7782 let users = self . load_storage_mapping ( storage) . await ?;
7883
79- self . cache . insert ( storage, CachedAccess :: new ( users) ) ;
84+ self . cache . insert (
85+ storage,
86+ if storage == 1 {
87+ CachedAccess :: with_ttl ( users, Duration :: from_secs ( 24 * 60 * 60 ) )
88+ } else {
89+ CachedAccess :: new ( users)
90+ } ,
91+ ) ;
8092 Ok ( self . cache . get ( & storage) . unwrap ( ) )
8193 }
8294 }
You can’t perform that action at this time.
0 commit comments