Search code examples
objective-cmapboxtilecache

Cleaning up RMDatabaseCache in RMTileCache


I'm using offline caching to download a preconfigured map from MapBox using:

tileCache = [[RMTileCache alloc] initWithExpiryPeriod:NSIntegerMax];
RMMapboxSource * tileSource = [[RMMapboxSource alloc] initWithMapID:mapID];
[tileCache beginBackgroundCacheForTileSource:tileSource southWest:southWest northEast:northEasth minZoom:minZoom maxZoom:maxZoom];

This all works fine and the result is a RMDatabaseCache object in the tileCache's tileCaches array.

My question is, how do I clean this specific cache up? I will have multiple of these caches, all with different map IDs and want to be able to clean up specific ones. Can't find a method that takes the mapID as a cleanup-key.

(my purpose is to have multiple offline maps, hence this approach)


Solution

  • Thought I'd share the solution that worked out for me. It's a bit of a workaround but gets the job done without jumping into the MapBox sourcecode and changing it internally:

    RMMapboxSource * tileSource = [[RMMapboxSource alloc] initWithMapID:MAP_ID];
    RMMapView *mapView = [[RMMapView alloc] initWithFrame:CGRectZero andTilesource:tileSource];
    [mapView removeAllCachedImages];
    

    Seems simple enough.

    I did have to modify the sourcecode at one point though, the database footprint didn't get smaller, so I had to jump into the MapBox code and change a line in the purseTiles:method in RMDatabaseCache as follows:

         [db executeUpdate:@"VACUUM"];