Skip to content

Commit

Permalink
Treat cache as promise
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed Jan 29, 2025
1 parent 63daf60 commit e8a7400
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/shared/akamai-edgeworker-sdk/src/api/LDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class LDClient extends LDClientImpl {
this._cacheableStoreProvider = storeProvider;
}

override initialized(): boolean {
return true;
}

override waitForInitialization(): Promise<LDClientType> {
// we need to resolve the promise immediately because Akamai's runtime doesnt
// have a setimeout so everything executes synchronously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { EdgeProvider } from '.';
* - 10 for enterprise
*/
export default class CacheableStoreProvider implements EdgeProvider {
cache: string | null | undefined;
cache: Promise<string | null | undefined> | null | undefined;
cachedAt: number | undefined;

constructor(
Expand All @@ -38,10 +38,7 @@ export default class CacheableStoreProvider implements EdgeProvider {
*/
async get(rootKey: string): Promise<string | null | undefined> {
if (!this._isCacheValid()) {
const updatedResults = await this._edgeProvider.get(rootKey);
if (updatedResults !== undefined) {
this.cache = updatedResults;
}
this.cache = this._edgeProvider.get(rootKey);
this.cachedAt = Date.now();
}

Expand Down

0 comments on commit e8a7400

Please sign in to comment.