summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-04-21 17:32:28 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-04-22 19:21:56 +0300
commit3bebd13d2e622b5c0c923747697044283945114c (patch)
treed90415692d381d28381aa41f33088340e26cbffd
parenteac6bdff16af09f8b3fc2f6d4a5bb781862b0f18 (diff)
downloadqtlocation-mapboxgl-3bebd13d2e622b5c0c923747697044283945114c.tar.gz
[core] Add Resource::StoragePolicy and consider it in resource loader
-rw-r--r--include/mbgl/storage/resource.hpp3
-rw-r--r--platform/default/src/mbgl/storage/database_file_source.cpp2
-rw-r--r--test/storage/main_resource_loader.test.cpp27
3 files changed, 32 insertions, 0 deletions
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp
index b7b394efc2..bee359e36d 100644
--- a/include/mbgl/storage/resource.hpp
+++ b/include/mbgl/storage/resource.hpp
@@ -33,6 +33,8 @@ public:
Offline
};
+ enum class StoragePolicy : bool { Permanent, Volatile };
+
struct TileData {
std::string urlTemplate;
uint8_t pixelRatio;
@@ -96,6 +98,7 @@ public:
optional<std::string> priorEtag = {};
std::shared_ptr<const std::string> priorData;
Duration minimumUpdateInterval{Duration::zero()};
+ StoragePolicy storagePolicy{StoragePolicy::Permanent};
};
inline bool Resource::hasLoadingMethod(Resource::LoadingMethod method) const {
diff --git a/platform/default/src/mbgl/storage/database_file_source.cpp b/platform/default/src/mbgl/storage/database_file_source.cpp
index 27424e1804..07a5291e05 100644
--- a/platform/default/src/mbgl/storage/database_file_source.cpp
+++ b/platform/default/src/mbgl/storage/database_file_source.cpp
@@ -179,6 +179,8 @@ std::unique_ptr<AsyncRequest> DatabaseFileSource::request(const Resource& resour
}
void DatabaseFileSource::forward(const Resource& res, const Response& response, std::function<void()> callback) {
+ if (res.storagePolicy == Resource::StoragePolicy::Volatile) return;
+
std::function<void()> wrapper;
if (callback) {
wrapper = Scheduler::GetCurrent()->bindOnce(std::move(callback));
diff --git a/test/storage/main_resource_loader.test.cpp b/test/storage/main_resource_loader.test.cpp
index 1bab30e1f8..9534aaa3fc 100644
--- a/test/storage/main_resource_loader.test.cpp
+++ b/test/storage/main_resource_loader.test.cpp
@@ -52,6 +52,33 @@ TEST(MainResourceLoader, TEST_REQUIRES_SERVER(CacheResponse)) {
loop.run();
}
+TEST(MainResourceLoader, TEST_REQUIRES_SERVER(VolatileStoragePolicy)) {
+ util::RunLoop loop;
+ MainResourceLoader fs(ResourceOptions{});
+
+ Resource resource{Resource::Unknown, "http://127.0.0.1:3000/cache"};
+ resource.storagePolicy = Resource::StoragePolicy::Volatile;
+
+ std::unique_ptr<AsyncRequest> req;
+ req = fs.request(resource, [&](Response res1) {
+ EXPECT_EQ(nullptr, res1.error);
+ ASSERT_TRUE(res1.data);
+ std::string firstData = *res1.data;
+
+ // Volatile resources are not stored in cache,
+ // so we always get new data from the server ("Response N+1").
+ req = fs.request(resource, [&](Response res2) {
+ req.reset();
+ EXPECT_EQ(nullptr, res2.error);
+ ASSERT_TRUE(res2.data);
+ EXPECT_NE(firstData, *res2.data);
+ loop.stop();
+ });
+ });
+
+ loop.run();
+}
+
TEST(MainResourceLoader, TEST_REQUIRES_SERVER(CacheRevalidateSame)) {
util::RunLoop loop;
MainResourceLoader fs(ResourceOptions{});