Authored by Justin R. Miller

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

... ... @@ -34,6 +34,8 @@
#import "RMConfiguration.h"
#import "RMTileSource.h"
#import "RMAbstractWebMapSource.h"
#import "RMTileCacheDownloadOperation.h"
@interface RMTileCache (Configuration)
... ... @@ -326,6 +328,8 @@
if (self.isBackgroundCaching)
return;
NSAssert([tileSource isKindOfClass:[RMAbstractWebMapSource class]], @"only web-based tile sources are supported for downloading");
_activeTileSource = tileSource;
_backgroundFetchQueue = [NSOperationQueue new];
... ...
... ... @@ -26,6 +26,8 @@
// POSSIBILITY OF SUCH DAMAGE.
#import "RMTileCacheDownloadOperation.h"
#import "RMAbstractWebMapSource.h"
#import "RMConfiguration.h"
@implementation RMTileCacheDownloadOperation
{
... ... @@ -39,6 +41,8 @@
if (!(self = [super init]))
return nil;
NSAssert([_source isKindOfClass:[RMAbstractWebMapSource class]], @"only web-based tile sources are supported for downloading");
_tile = tile;
_source = source;
_cache = cache;
... ... @@ -54,13 +58,27 @@
if ([self isCancelled])
return;
if ( ! [_cache cachedImage:_tile withCacheKey:[_source uniqueTilecacheKey]])
if ( ! [_cache cachedImage:_tile withCacheKey:[_source uniqueTilecacheKey] bypassingMemoryCache:YES])
{
if ([self isCancelled])
return;
if ( ! [_source imageForTile:_tile inCache:_cache])
NSURL *tileURL = [(RMAbstractWebMapSource *)_source URLForTile:_tile];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:tileURL];
request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
NSError *error = nil;
NSData *data = [NSURLConnection sendBrandedSynchronousRequest:request
returningResponse:nil
error:&error];
if ( ! data || error != nil)
{
[self cancel];
}
else
{
[_cache addDiskCachedImageData:data forTile:_tile withCacheKey:[_source uniqueTilecacheKey]];
}
}
}
... ...