Skip to content

Commit

Permalink
Expose clearAmbientCache method (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
OdNairy authored Nov 25, 2024
1 parent e4f30f2 commit c2bb275
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ In order to continue use them use the following import `@_spi(Experimental) impo
* Fix a crash on calling `LocationIndicatorLayer/location(coordinate:) function` due to missing 0 altitude value.
* Add a new Expression initializer `init(_ operator: Operator, _ arguments: ExpressionArgumentConvertible...)` to simplify the creation of expressions with multiple arguments.
That initializer doesn't require to wrap arguments in `Argument` cases. For example, `Exp(.eq, Exp(.get, "extrude"), "true")`.
* Expose a `TileStore/clearAmbientCache()` method to clear ambient cache.
* Add new experimental `radius` parameter to `TapInteraction`, `LongPressInteraction` and interaction managers to control the radius of a tappable area.

## 11.8.0 - 11 November, 2024
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- ``MapboxCommon/TileRegionEstimateProgressCallback``
- ``MapboxCommon/CacheClearingError``
- ``MapboxCommon/CacheClearingErrorType``
- ``ClearCacheError``

### Style pack

Expand Down
17 changes: 17 additions & 0 deletions Sources/MapboxMaps/Offline/ClearCacheError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// Describes the reason for a cache clearing failure.
public enum ClearCacheError: Error, Equatable, Sendable, CoreErrorRepresentable {

/// There was an issue accessing the database
case database(String)

/// There was an uncategorised error, check the associated message
case other(String)

init(coreError: MapboxCommon.CacheClearingError) {
switch coreError.type {
case .databaseError: self = .database(coreError.message)
case .otherError: fallthrough
@unknown default: self = .other(coreError.message)
}
}
}
26 changes: 26 additions & 0 deletions Sources/MapboxMaps/Offline/TileStore+MapboxMaps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,32 @@ extension TileStore: TileStoreProtocol {
public func removeRegion(forId id: String, completion: @escaping (Result<TileRegion, Error>) -> Void) {
__removeTileRegion(forId: id, callback: tileStoreClosureAdapter(for: completion, type: TileRegion.self))
}

/// Clears the ambient cache data.
///
/// Ambient cache data is anything not associated with an offline region or a stylepack,
/// including predictively cached data. Use to quickly clear data e.g. for a system update.
///
/// Note: Do not use this method to clear cache data unless strictly
/// necessary as previously cached data will need to be re-downloaded,
/// leading to increased network usage.
/// If you want general control of the size of the Tile Store.
///
/// - Note: This function is blocking the Tile Store until completed.
/// - Parameter completion: The `UInt32` value represents how many bytes were cleared from the cache.
public func clearAmbientCache(
completion: @escaping (Result<UInt32, any Error>) -> Void
) {
clearAmbientCache(
forCallback: coreAPIClosureAdapter(
for: completion,
type: NSNumber.self,
concreteErrorType: ClearCacheError.self,
converter: { $0.uint32Value }
)
)
}

}

private func tileStoreClosureAdapter<T, ObjCType>(
Expand Down

0 comments on commit c2bb275

Please sign in to comment.