[darwin] Add MGLOfflineStorage putResourceForURL
Useful for pre-warming the ambient cache
This commit is contained in:
@@ -339,6 +339,26 @@ MGL_EXPORT
|
||||
*/
|
||||
@property (nonatomic, readonly) unsigned long long countOfBytesCompleted;
|
||||
|
||||
/*
|
||||
* Insert the provided resource into the ambient cache
|
||||
* This method mimics the caching that would take place if the equivalent
|
||||
* resource were requested in the process of map rendering.
|
||||
* Use this method to pre-warm the cache with resources you know
|
||||
* will be requested.
|
||||
*
|
||||
* This call is asynchronous: the data may not be immediately available
|
||||
* for in-progress requests, although subsequent requests should have
|
||||
* access to the cached data.
|
||||
*
|
||||
* @param url The URL of the resource to insert
|
||||
* @param data Response data to store for this resource. Data is expected to be uncompressed; internally, the cache will compress data as necessary.
|
||||
* @param modified Optional "modified" response header
|
||||
* @param expires Optional "expires" response header
|
||||
* @param etag Optional "entity tag" response header
|
||||
*/
|
||||
-(void)putResourceWithUrl:(NSURL *)url data:(NSData *)data modified:(NSDate * _Nullable)modified expires:(NSDate * _Nullable)expires etag:(NSString * _Nullable)etag;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
#import "MGLTilePyramidOfflineRegion.h"
|
||||
#import "NSBundle+MGLAdditions.h"
|
||||
#import "NSValue+MGLAdditions.h"
|
||||
#import "NSDate+MGLAdditions.h"
|
||||
#import "NSData+MGLAdditions.h"
|
||||
|
||||
#include <mbgl/actor/actor.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/storage/resource_transform.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
|
||||
@@ -470,4 +473,25 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
|
||||
return attributes.fileSize;
|
||||
}
|
||||
|
||||
-(void)putResourceWithUrl:(NSURL *)url data:(NSData *)data modified:(NSDate * _Nullable)modified expires:(NSDate * _Nullable)expires etag:(NSString * _Nullable)etag {
|
||||
mbgl::Resource resource(mbgl::Resource::Kind::Unknown, [[url absoluteString] UTF8String]);
|
||||
mbgl::Response response;
|
||||
response.data = std::make_shared<std::string>(static_cast<const char*>(data.bytes), data.length);
|
||||
|
||||
if (etag) {
|
||||
response.etag = std::string([etag UTF8String]);
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
response.modified = mbgl::util::now() + std::chrono::duration_cast<mbgl::Seconds>(MGLDurationFromTimeInterval(modified.timeIntervalSinceNow));
|
||||
}
|
||||
|
||||
if (expires) {
|
||||
response.expires = mbgl::util::now() + std::chrono::duration_cast<mbgl::Seconds>(MGLDurationFromTimeInterval(expires.timeIntervalSinceNow));
|
||||
}
|
||||
|
||||
_mbglFileSource->put(resource, response);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user