Skip to content

Commit 97a4482

Browse files
committed
add clearCache
1 parent cdb9bc8 commit 97a4482

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

packages/core/src/codewhisperer/region/regionProfileManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ export class RegionProfileManager {
373373
}
374374
}
375375

376+
// Should be called on connection changed in case users change to a differnet connection and use the wrong resultset.
377+
async clearCache() {
378+
await this.cache.clearCache()
379+
}
380+
376381
async createQClient(region: string, endpoint: string, conn: SsoConnection): Promise<CodeWhispererUserClient> {
377382
const token = (await conn.getToken()).accessToken
378383
const serviceOption: ServiceOptions = {

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export class AuthUtil {
143143
if (!this.isConnected()) {
144144
await this.regionProfileManager.invalidateProfile(this.regionProfileManager.activeRegionProfile?.arn)
145145
}
146+
147+
await this.regionProfileManager.clearCache()
146148
})
147149

148150
this.regionProfileManager.onDidChangeRegionProfile(async () => {

packages/core/src/shared/utilities/resourceCache.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ export abstract class CachedResource<V> {
154154
}
155155
}
156156

157+
async clearCache() {
158+
const baseCache = this.readCacheOrDefault()
159+
await this.updateResourceCache({ result: undefined, timestamp: 0, locked: false }, baseCache)
160+
}
161+
157162
private async updateResourceCache(resource: Partial<Resource<any>>, cache: GlobalStateSchema<any> | undefined) {
158163
const baseCache = cache ?? this.readCacheOrDefault()
159164

0 commit comments

Comments
 (0)