Skip to content

Commit c2bb275

Browse files
authored
Expose clearAmbientCache method (#2367)
1 parent e4f30f2 commit c2bb275

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ In order to continue use them use the following import `@_spi(Experimental) impo
1616
* Fix a crash on calling `LocationIndicatorLayer/location(coordinate:) function` due to missing 0 altitude value.
1717
* Add a new Expression initializer `init(_ operator: Operator, _ arguments: ExpressionArgumentConvertible...)` to simplify the creation of expressions with multiple arguments.
1818
That initializer doesn't require to wrap arguments in `Argument` cases. For example, `Exp(.eq, Exp(.get, "extrude"), "true")`.
19+
* Expose a `TileStore/clearAmbientCache()` method to clear ambient cache.
1920
* Add new experimental `radius` parameter to `TapInteraction`, `LongPressInteraction` and interaction managers to control the radius of a tappable area.
2021

2122
## 11.8.0 - 11 November, 2024

Sources/MapboxMaps/Documentation.docc/API Catalogs/TileStore APIs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- ``MapboxCommon/TileRegionEstimateProgressCallback``
3636
- ``MapboxCommon/CacheClearingError``
3737
- ``MapboxCommon/CacheClearingErrorType``
38+
- ``ClearCacheError``
3839

3940
### Style pack
4041

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// Describes the reason for a cache clearing failure.
2+
public enum ClearCacheError: Error, Equatable, Sendable, CoreErrorRepresentable {
3+
4+
/// There was an issue accessing the database
5+
case database(String)
6+
7+
/// There was an uncategorised error, check the associated message
8+
case other(String)
9+
10+
init(coreError: MapboxCommon.CacheClearingError) {
11+
switch coreError.type {
12+
case .databaseError: self = .database(coreError.message)
13+
case .otherError: fallthrough
14+
@unknown default: self = .other(coreError.message)
15+
}
16+
}
17+
}

Sources/MapboxMaps/Offline/TileStore+MapboxMaps.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,32 @@ extension TileStore: TileStoreProtocol {
241241
public func removeRegion(forId id: String, completion: @escaping (Result<TileRegion, Error>) -> Void) {
242242
__removeTileRegion(forId: id, callback: tileStoreClosureAdapter(for: completion, type: TileRegion.self))
243243
}
244+
245+
/// Clears the ambient cache data.
246+
///
247+
/// Ambient cache data is anything not associated with an offline region or a stylepack,
248+
/// including predictively cached data. Use to quickly clear data e.g. for a system update.
249+
///
250+
/// Note: Do not use this method to clear cache data unless strictly
251+
/// necessary as previously cached data will need to be re-downloaded,
252+
/// leading to increased network usage.
253+
/// If you want general control of the size of the Tile Store.
254+
///
255+
/// - Note: This function is blocking the Tile Store until completed.
256+
/// - Parameter completion: The `UInt32` value represents how many bytes were cleared from the cache.
257+
public func clearAmbientCache(
258+
completion: @escaping (Result<UInt32, any Error>) -> Void
259+
) {
260+
clearAmbientCache(
261+
forCallback: coreAPIClosureAdapter(
262+
for: completion,
263+
type: NSNumber.self,
264+
concreteErrorType: ClearCacheError.self,
265+
converter: { $0.uint32Value }
266+
)
267+
)
268+
}
269+
244270
}
245271

246272
private func tileStoreClosureAdapter<T, ObjCType>(

0 commit comments

Comments
 (0)