Skip to content

Commit

Permalink
refactor: rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
confidence-bot authored and nicklasl committed Aug 20, 2024
1 parent c9922b8 commit ecb1c29
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export class ConfidenceReact implements EventSender, Trackable, FlagResolver {
clearContext({ transition }?: {
transition?: boolean | undefined;
}): void;
clearFlagCache(): void;
get config(): Configuration;
// @internal
get contextState(): string;
// @internal
readonly delegate: Confidence;
evaluateFlag<T extends Value>(path: string, defaultValue: T): FlagEvaluation<Value.Widen<T>>;
evictFlagCache(): void;
getContext(): Context;
getFlag<T extends Value>(path: string, defaultValue: T): Promise<Value.Widen<T>>;
setContext(context: Context, { transition }?: {
Expand Down
6 changes: 3 additions & 3 deletions api/sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type Closer = () => void;
export class Confidence implements EventSender, Trackable, FlagResolver {
constructor(config: Configuration, parent?: Confidence);
clearContext(): void;
clearFlagCache(): void;
readonly config: Configuration;
// Warning: (ae-forgotten-export) The symbol "Subscribe" needs to be exported by the entry point index.d.ts
//
Expand All @@ -24,7 +25,6 @@ export class Confidence implements EventSender, Trackable, FlagResolver {
static create({ clientSecret, region, timeout, environment, flagCacheTtl, fetchImplementation, logger, }: ConfidenceOptions): Confidence;
get environment(): string;
evaluateFlag<T extends Value>(path: string, defaultValue: T): FlagEvaluation<Value.Widen<T>>;
evictFlagCache(): void;
get flagState(): State;
getContext(): Context;
getFlag<T extends Value>(path: string, defaultValue: T): Promise<Value.Widen<T>>;
Expand Down Expand Up @@ -126,9 +126,9 @@ export type FlagEvaluation<T> = FlagEvaluation.Resolved<T> | FlagEvaluation.Stal

// @public
export interface FlagResolver extends Contextual<FlagResolver> {
evaluateFlag<T extends Value>(path: string, defaultValue: T): FlagEvaluation<Value.Widen<T>>;
// (undocumented)
evictFlagCache(): void;
clearFlagCache(): void;
evaluateFlag<T extends Value>(path: string, defaultValue: T): FlagEvaluation<Value.Widen<T>>;
getFlag<T extends Value>(path: string, defaultValue: T): Promise<Value.Widen<T>>;
subscribe(onStateChange?: StateObserver): () => void;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/react18/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function App() {
</Boundary>
</Suspense>
</Level>
<button onClick={() => confidence.evictFlagCache()}>Evict Cache</button>
<button onClick={() => confidence.clearFlagCache()}>Evict Cache</button>
</Suspense>
</ConfidenceProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const confidenceMock: jest.Mocked<FlagResolver> = {
clearContext: jest.fn(),
subscribe: jest.fn(),
evaluateFlag: jest.fn(),
evictFlagCache: jest.fn(),
clearFlagCache: jest.fn(),
getFlag: jest.fn(),
};

Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ export class ConfidenceReact implements EventSender, Trackable, FlagResolver {
}

/**
* Evicts the flag cache
* Clear the flag cache
*/
evictFlagCache(): void {
this.delegate.evictFlagCache();
clearFlagCache(): void {
this.delegate.clearFlagCache();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ const confidence = Confidence.create({

The client side version of the SDK has in memory caching enabled by default. This mean that it will keep the flag value (resolved flag data) in memory until the page is refreshed to maintain a consistent user experience.

This can be configured using the `flagCacheTtl` option if you need a shorter TTL. You can also use the `evictFlagCache()` function there is need to evict the flags based on some other signal.
This can be configured using the `flagCacheTtl` option if you need a shorter TTL. You can also use the `clearFlagCache()` function there is need to evict the flags based on some other signal.

```ts
const confidence = Confidence.create({
flagCacheTtl: 10_000, // flag cache ttl in milliseconds
// ... other options
});

confidence.evictFlagCache(); // forcefully evict the flag cache
confidence.clearFlagCache(); // forcefully evict the flag cache
```

### Timeout
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk/src/Confidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,8 @@ export class Confidence implements EventSender, Trackable, FlagResolver {
}
}

/**
* Evicts flag cache
*/
evictFlagCache(): void {
/** Clears flag cache */
clearFlagCache(): void {
if (this.config.flagResolverClient instanceof CachingFlagResolverClient) {
(this.config.flagResolverClient as CachingFlagResolverClient).forceEvict();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ export interface FlagResolver extends Contextual<FlagResolver> {
/** Returns flag value for a given flag */
getFlag<T extends Value>(path: string, defaultValue: T): Promise<Value.Widen<T>>;

evictFlagCache(): void;
clearFlagCache(): void;
}

0 comments on commit ecb1c29

Please sign in to comment.