Overview
src/hooks/useStreamingData.ts (and callers in video, quiz, and course modules) calls getAccessToken() from secureStorage.ts independently for each streaming connection. getAccessToken reads from expo-secure-store, which involves a native bridge call. Under normal usage with 3 concurrent streams (video + progress + notifications), this results in 3 sequential native bridge calls per token read cycle (token is read on reconnect, on retry, and on each new stream).
Specifications
Features:
- Token cached in memory for 60-second window (refreshed when approaching expiry)
- All streaming connections share the same in-memory token cache
- Cache invalidated on token refresh or logout
Tasks:
- Add in-memory token cache in
src/services/secureStorage.ts: { token: string, expiresAt: number } | null
getAccessToken() returns cached value if Date.now() < expiresAt - 30000
- Cache cleared in
clearTokens() and saveTokens()
- Add unit test confirming single SecureStore read for 3 rapid
getAccessToken() calls
- Cache TTL configurable via constant
Impacted Files:
src/services/secureStorage.ts
Acceptance Criteria
- 3 calls to
getAccessToken() within 1 second result in 1 native bridge call
- Cache is invalidated after
saveTokens() or clearTokens()
- Cache TTL default is 60 seconds
- Unit test confirms single
SecureStore.getItemAsync invocation for 3 rapid calls
Overview
src/hooks/useStreamingData.ts(and callers in video, quiz, and course modules) callsgetAccessToken()fromsecureStorage.tsindependently for each streaming connection.getAccessTokenreads fromexpo-secure-store, which involves a native bridge call. Under normal usage with 3 concurrent streams (video + progress + notifications), this results in 3 sequential native bridge calls per token read cycle (token is read on reconnect, on retry, and on each new stream).Specifications
Features:
Tasks:
src/services/secureStorage.ts:{ token: string, expiresAt: number } | nullgetAccessToken()returns cached value ifDate.now() < expiresAt - 30000clearTokens()andsaveTokens()getAccessToken()callsImpacted Files:
src/services/secureStorage.tsAcceptance Criteria
getAccessToken()within 1 second result in 1 native bridge callsaveTokens()orclearTokens()SecureStore.getItemAsyncinvocation for 3 rapid calls