mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 01:28:26 -05:00
Add Simple Account Picker for use with Always Encrypted (#9707)
Adds the ability for the user to select from two or more linked azure accounts, using an integrated UI dialog, when executing a query that requires a Always Encrypted column master key located in Azure Key Vault.
This commit is contained in:
37
extensions/mssql/src/util/dataCache.ts
Normal file
37
extensions/mssql/src/util/dataCache.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export class DataItemCache<T> {
|
||||
|
||||
millisecondsToLive: number;
|
||||
getValueFunction: (...args: any[]) => Promise<T>;
|
||||
cachedItem: T;
|
||||
fetchDate: Date;
|
||||
|
||||
constructor(getValueFunction: (...args: any[]) => Promise<T>, secondsToLive: number) {
|
||||
this.millisecondsToLive = secondsToLive * 1000;
|
||||
this.getValueFunction = getValueFunction;
|
||||
this.cachedItem = undefined;
|
||||
this.fetchDate = new Date(0);
|
||||
}
|
||||
|
||||
public isCacheExpired(): boolean {
|
||||
return (this.fetchDate.getTime() + this.millisecondsToLive) < new Date().getTime();
|
||||
}
|
||||
|
||||
public async getData(...args: any[]): Promise<T> {
|
||||
if (!this.cachedItem || this.isCacheExpired()) {
|
||||
let data = await this.getValueFunction(...args);
|
||||
this.cachedItem = data;
|
||||
this.fetchDate = new Date();
|
||||
return data;
|
||||
}
|
||||
return this.cachedItem;
|
||||
}
|
||||
|
||||
public resetCache(): void {
|
||||
this.fetchDate = new Date(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user