Skip to content

Commit

Permalink
fix: do not initialize cache when flag is off (#8969)
Browse files Browse the repository at this point in the history
This feature is still in early alpha. We do not want to populate any
cache on startup. We might not want to do it ever.
  • Loading branch information
sjaanus authored Dec 12, 2024
1 parent de7b95a commit c0925ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
IFeatureToggleClient,
IFeatureToggleClientStore,
IFeatureToggleQuery,
IFlagResolver,
} from '../../../types';
import type { FeatureConfigurationClient } from '../../feature-toggle/types/feature-toggle-strategies-store-type';
import type ConfigurationRevisionService from '../../feature-toggle/configuration-revision-service';
Expand Down Expand Up @@ -99,19 +100,23 @@ export class ClientFeatureToggleCache {

private interval: NodeJS.Timer;

private flagResolver: IFlagResolver;

private configurationRevisionService: ConfigurationRevisionService;

constructor(
clientFeatureToggleStore: IFeatureToggleClientStore,
eventStore: IEventStore,
configurationRevisionService: ConfigurationRevisionService,
flagResolver: IFlagResolver,
) {
this.eventStore = eventStore;
this.configurationRevisionService = configurationRevisionService;
this.clientFeatureToggleStore = clientFeatureToggleStore;
this.flagResolver = flagResolver;
this.onUpdateRevisionEvent = this.onUpdateRevisionEvent.bind(this);

this.initCache();
// this.initCache(); TODO: we dont want to initialize cache on startup, but ondemand in future?
this.configurationRevisionService.on(
UPDATE_REVISION,
this.onUpdateRevisionEvent,
Expand Down Expand Up @@ -158,7 +163,9 @@ export class ClientFeatureToggleCache {
}

private async onUpdateRevisionEvent() {
await this.pollEvents();
if (this.flagResolver.isEnabled('deltaApi')) {
await this.pollEvents();
}
}

public async pollEvents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const createClientFeatureToggleCache = (
featureToggleClientStore,
eventStore,
configurationRevisionService,
flagResolver,
);

return clientFeatureToggleCache;
Expand Down

0 comments on commit c0925ea

Please sign in to comment.