Skip to content

Commit 2f0d71e

Browse files
authored
Merge pull request #460 from qonversion/kamo/dev-1236-sdk-iosandroid-obvyazki-refetch-rc-posle-identify-i-yavnii
feat: expose invalidateRemoteConfigsCache, bump sandwich to 7.12.0 (DEV-1236)
2 parents 03eaee7 + 0eb0dd8 commit 2f0d71e

9 files changed

Lines changed: 61 additions & 2 deletions

File tree

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
8080
dependencies {
8181
implementation "com.facebook.react:react-android"
8282
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
83-
implementation "io.qonversion:sandwich:7.11.0"
83+
implementation "io.qonversion:sandwich:7.12.0"
8484
}
8585

8686
if (isNewArchitectureEnabled()) {

android/src/main/java/com/qonversion/reactnativesdk/QonversionModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ class QonversionModule(reactContext: ReactApplicationContext) : NativeQonversion
246246
)
247247
}
248248

249+
@ReactMethod
250+
override fun invalidateRemoteConfigsCache() {
251+
qonversionSandwich.invalidateRemoteConfigsCache()
252+
}
253+
249254
@ReactMethod
250255
override fun attachUserToExperiment(experimentId: String, groupId: String, promise: Promise) {
251256
qonversionSandwich.attachUserToExperiment(experimentId, groupId, getResultListener(promise))

ios/RNQonversion.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ - (void)remoteConfigListForContextKeys:(NSArray<NSString *> *)contextKeys includ
258258
}
259259
}
260260

261+
- (void)invalidateRemoteConfigsCache {
262+
@try {
263+
[self.impl invalidateRemoteConfigsCache];
264+
} @catch (NSException *exception) {
265+
QNR_LOG_EXCEPTION("invalidateRemoteConfigsCache", exception);
266+
}
267+
}
268+
261269
- (void)attachUserToExperiment:(NSString *)experimentId groupId:(NSString *)groupId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
262270
@try {
263271
[self.impl attachUserToExperiment:experimentId groupId:groupId resolve:resolve reject:reject];

ios/RNQonversionImpl.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ public class RNQonversionImpl: NSObject {
196196
}
197197
}
198198

199+
@objc
200+
public func invalidateRemoteConfigsCache() {
201+
qonversionSandwich?.invalidateRemoteConfigsCache()
202+
}
203+
199204
@objc
200205
public func attachUserToExperiment(_ experimentId: String, groupId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
201206
qonversionSandwich?.attachUserToExperiment(with: experimentId, groupId: groupId) { result, error in

qonversion-react-native-sdk.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ Pod::Spec.new do |s|
1616
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
1717
s.private_header_files = "ios/**/*.h"
1818

19-
s.dependency "QonversionSandwich", "7.11.0"
19+
s.dependency "QonversionSandwich", "7.12.0"
2020
install_modules_dependencies(s)
2121
end

src/QonversionApi.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,31 @@ export interface QonversionApi {
324324
*/
325325
remoteConfigListForContextKeys(contextKeys: string[], includeEmptyContextKey: boolean): Promise<RemoteConfigList>
326326

327+
/**
328+
* Invalidates the cache of remote configs so the next {@link remoteConfig} or
329+
* {@link remoteConfigList} call fetches a fresh targeting evaluation from the
330+
* server instead of returning the cached copy.
331+
*
332+
* This method performs no network request itself — it only marks the cached
333+
* values as stale. An in-flight remoteConfig load is re-issued once so its
334+
* waiting calls receive a fresh evaluation; an in-flight remoteConfigList
335+
* completes with the evaluation it started with.
336+
*
337+
* Call it when the targeting inputs changed and you need the change reflected
338+
* immediately, for example after setting a batch of user properties your
339+
* remote config targeting depends on. You do NOT need to call it after
340+
* {@link identify} — the SDK invalidates the cache on identity changes
341+
* automatically.
342+
*
343+
* If the re-issued load fails, the previously received evaluation is
344+
* delivered instead of an error — the call never degrades below the
345+
* pre-invalidation result.
346+
*
347+
* Call it after {@link Qonversion.initialize}: calling before initialization
348+
* throws on Android and does nothing on iOS.
349+
*/
350+
invalidateRemoteConfigsCache(): void;
351+
327352
/**
328353
* This function should be used for the test purposes only. Do not forget to delete the usage of this function before the release.
329354
* Use this function to attach the user to the experiment.

src/internal/QonversionInternal.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ export default class QonversionInternal implements QonversionApi {
376376
return mappedRemoteConfigList;
377377
}
378378

379+
invalidateRemoteConfigsCache() {
380+
RNQonversion.invalidateRemoteConfigsCache();
381+
}
382+
379383
async attachUserToExperiment(experimentId: string, groupId: string): Promise<void> {
380384
await RNQonversion.attachUserToExperiment(experimentId, groupId);
381385
return;

src/internal/__tests__/QonversionInternal.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jest.mock('../specs/NativeQonversionModule', () => ({
2525
}),
2626
onPromoPurchaseReceived: jest.fn(),
2727
purchaseWithResult: jest.fn(),
28+
invalidateRemoteConfigsCache: jest.fn(),
2829
},
2930
}));
3031

@@ -252,3 +253,13 @@ describe('QonversionInternal - setDeferredPurchasesListener replaces wrapped ent
252253
expect(RNQonversion.onDeferredPurchaseCompleted).toHaveBeenCalledTimes(1);
253254
});
254255
});
256+
257+
describe('invalidateRemoteConfigsCache', () => {
258+
it('passes the call straight through to the native module', () => {
259+
const instance = new QonversionInternal(createConfig());
260+
261+
instance.invalidateRemoteConfigsCache();
262+
263+
expect(RNQonversion.invalidateRemoteConfigsCache).toHaveBeenCalledTimes(1);
264+
});
265+
});

src/internal/specs/NativeQonversionModule.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface Spec extends TurboModule {
7373
remoteConfig(contextKey: string | undefined): Promise<QRemoteConfig>;
7474
remoteConfigList(): Promise<QRemoteConfigList>;
7575
remoteConfigListForContextKeys(contextKeys: string[], includeEmptyContextKey: boolean): Promise<QRemoteConfigList>;
76+
invalidateRemoteConfigsCache(): void;
7677
attachUserToExperiment(experimentId: string, groupId: string): Promise<void>;
7778
detachUserFromExperiment(experimentId: string): Promise<void>;
7879
attachUserToRemoteConfiguration(remoteConfigurationId: string): Promise<void>;

0 commit comments

Comments
 (0)