Cleaning up RMDatabaseCache in RMTileCache

345 views Asked by At

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)

2

There are 2 answers

0
Yasper On BEST ANSWER

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"];
1
incanus On

There isn't an API for this, but have a look at -[RMTileCache removeAllCachedImagesForCacheKey:] and the source of the tile source(s) in question to see how they construct the cacheKey in order to do this.