Authored by Justin R. Miller

bypass memory cache, cache policy, and normal tile source fetches

@@ -34,6 +34,8 @@ @@ -34,6 +34,8 @@
34 #import "RMConfiguration.h" 34 #import "RMConfiguration.h"
35 #import "RMTileSource.h" 35 #import "RMTileSource.h"
36 36
  37 +#import "RMAbstractWebMapSource.h"
  38 +
37 #import "RMTileCacheDownloadOperation.h" 39 #import "RMTileCacheDownloadOperation.h"
38 40
39 @interface RMTileCache (Configuration) 41 @interface RMTileCache (Configuration)
@@ -326,6 +328,8 @@ @@ -326,6 +328,8 @@
326 if (self.isBackgroundCaching) 328 if (self.isBackgroundCaching)
327 return; 329 return;
328 330
  331 + NSAssert([tileSource isKindOfClass:[RMAbstractWebMapSource class]], @"only web-based tile sources are supported for downloading");
  332 +
329 _activeTileSource = tileSource; 333 _activeTileSource = tileSource;
330 334
331 _backgroundFetchQueue = [NSOperationQueue new]; 335 _backgroundFetchQueue = [NSOperationQueue new];
@@ -26,6 +26,8 @@ @@ -26,6 +26,8 @@
26 // POSSIBILITY OF SUCH DAMAGE. 26 // POSSIBILITY OF SUCH DAMAGE.
27 27
28 #import "RMTileCacheDownloadOperation.h" 28 #import "RMTileCacheDownloadOperation.h"
  29 +#import "RMAbstractWebMapSource.h"
  30 +#import "RMConfiguration.h"
29 31
30 @implementation RMTileCacheDownloadOperation 32 @implementation RMTileCacheDownloadOperation
31 { 33 {
@@ -39,6 +41,8 @@ @@ -39,6 +41,8 @@
39 if (!(self = [super init])) 41 if (!(self = [super init]))
40 return nil; 42 return nil;
41 43
  44 + NSAssert([_source isKindOfClass:[RMAbstractWebMapSource class]], @"only web-based tile sources are supported for downloading");
  45 +
42 _tile = tile; 46 _tile = tile;
43 _source = source; 47 _source = source;
44 _cache = cache; 48 _cache = cache;
@@ -54,13 +58,27 @@ @@ -54,13 +58,27 @@
54 if ([self isCancelled]) 58 if ([self isCancelled])
55 return; 59 return;
56 60
57 - if ( ! [_cache cachedImage:_tile withCacheKey:[_source uniqueTilecacheKey]]) 61 + if ( ! [_cache cachedImage:_tile withCacheKey:[_source uniqueTilecacheKey] bypassingMemoryCache:YES])
58 { 62 {
59 if ([self isCancelled]) 63 if ([self isCancelled])
60 return; 64 return;
61 65
62 - if ( ! [_source imageForTile:_tile inCache:_cache]) 66 + NSURL *tileURL = [(RMAbstractWebMapSource *)_source URLForTile:_tile];
  67 + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:tileURL];
  68 + request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
  69 + NSError *error = nil;
  70 + NSData *data = [NSURLConnection sendBrandedSynchronousRequest:request
  71 + returningResponse:nil
  72 + error:&error];
  73 +
  74 + if ( ! data || error != nil)
  75 + {
63 [self cancel]; 76 [self cancel];
  77 + }
  78 + else
  79 + {
  80 + [_cache addDiskCachedImageData:data forTile:_tile withCacheKey:[_source uniqueTilecacheKey]];
  81 + }
64 } 82 }
65 } 83 }
66 84