Skip to content

Commit ff7b29d

Browse files
authored
refactor(dart): remove access token request cache (#29)
1 parent 7723757 commit ff7b29d

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

lib/logto_client.dart

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ class LogtoClient {
2323

2424
static late TokenStorage _tokenStorage;
2525

26-
/// Logto automatically enables refresh token's rotation
27-
///
28-
/// Simultaneous access token request may be problematic
29-
/// Use a request cache map to avoid the race condition
30-
static final Map<String, Future<AccessToken?>> _accessTokenRequestCache = {};
31-
3226
/// Custom [http.Client].
3327
///
3428
/// Note that you will have to call `close()` yourself when passing a [http.Client] instance.
@@ -81,21 +75,7 @@ class LogtoClient {
8175
return accessToken;
8276
}
8377

84-
// If no valid access token is found in storage, use refresh token to claim a new one
85-
final cacheKey = TokenStorage.buildAccessTokenKey(resource);
86-
87-
// Reuse the cached request if is exist
88-
if (_accessTokenRequestCache[cacheKey] != null) {
89-
return _accessTokenRequestCache[cacheKey];
90-
}
91-
92-
// Create new token request and add it to cache
93-
final newTokenRequest = _getAccessTokenByRefreshToken(resource);
94-
_accessTokenRequestCache[cacheKey] = newTokenRequest;
95-
96-
final token = await newTokenRequest;
97-
// Clear the cache after response
98-
_accessTokenRequestCache.remove(cacheKey);
78+
final token = await _getAccessTokenByRefreshToken(resource);
9979

10080
return token;
10181
}

0 commit comments

Comments
 (0)