Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add invalidateAmbientCache method #899

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ public void onError(String error) {
});
}

@ReactMethod
public void invalidateAmbientCache(final Promise promise) {
activateFileSource();
final OfflineManager offlineManager = OfflineManager.getInstance(mReactContext);
offlineManager.invalidateAmbientCache(new OfflineManager.FileSourceCallback() {
@Override
public void onSuccess() {
promise.resolve(null);
}

@Override
public void onError(String error) {
promise.reject("invalidateAmbientCache", error);
}
});
}


@ReactMethod
public void resetDatabase(final Promise promise) {
activateFileSource();
Expand Down
16 changes: 16 additions & 0 deletions docs/OfflineManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ await MapboxGL.offlineManager.deletePack('packName')
```


#### invalidateAmbientCache()

Forces a revalidation of the tiles in the ambient cache and downloads a fresh version of the tiles from the tile server.<br/>This is the recommend method for clearing the cache.<br/>This is the most efficient method because tiles in the ambient cache are re-downloaded to remove outdated data from a device.<br/>It does not erase resources from the ambient cache or delete the database, which can be computationally expensive operations that may carry unintended side effects.

##### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |




```javascript
await MapboxGL.offlineManager.invalidateAmbientCache();
```


#### resetDatabase()

Deletes the existing database, which includes both the ambient cache and offline packs, then reinitializes it.
Expand Down
14 changes: 14 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5573,6 +5573,20 @@
}
}
},
{
"name": "invalidateAmbientCache",
"description": "Forces a revalidation of the tiles in the ambient cache and downloads a fresh version of the tiles from the tile server.\nThis is the recommend method for clearing the cache.\nThis is the most efficient method because tiles in the ambient cache are re-downloaded to remove outdated data from a device.\nIt does not erase resources from the ambient cache or delete the database, which can be computationally expensive operations that may carry unintended side effects.",
"params": [],
"examples": [
"await MapboxGL.offlineManager.invalidateAmbientCache();"
],
"returns": {
"description": "",
"type": {
"name": "void"
}
}
},
{
"name": "resetDatabase",
"description": "Deletes the existing database, which includes both the ambient cache and offline packs, then reinitializes it.",
Expand Down
11 changes: 11 additions & 0 deletions ios/RCTMGL/MGLOfflineModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
});
}

RCT_EXPORT_METHOD(invalidateAmbientCache:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
[[MGLOfflineStorage sharedOfflineStorage] invalidateAmbientCacheWithCompletionHandler:^(NSError *error) {
if (error != nil) {
reject(@"invalidateAmbientCache", error.description, error);
return;
}
resolve(nil);
}];
}

RCT_EXPORT_METHOD(resetDatabase:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
[[MGLOfflineStorage sharedOfflineStorage] resetDatabaseWithCompletionHandler:^(NSError *error) {
Expand Down
16 changes: 16 additions & 0 deletions javascript/modules/offline/offlineManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ class OfflineManager {
}
}

/**
* Forces a revalidation of the tiles in the ambient cache and downloads a fresh version of the tiles from the tile server.
* This is the recommend method for clearing the cache.
* This is the most efficient method because tiles in the ambient cache are re-downloaded to remove outdated data from a device.
* It does not erase resources from the ambient cache or delete the database, which can be computationally expensive operations that may carry unintended side effects.
*
* @example
* await MapboxGL.offlineManager.invalidateAmbientCache();
*
* @return {void}
*/
async invalidateAmbientCache() {
await this._initialize();
await MapboxGLOfflineManager.invalidateAmbientCache();
}

/**
* Deletes the existing database, which includes both the ambient cache and offline packs, then reinitializes it.
*
Expand Down