diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-01-08 13:05:51 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-01-08 13:05:51 +0100 |
commit | 4479f5db6c1ce26bc187a1b5a938f4bdb45915d4 (patch) | |
tree | 6344edec69099fe3bef3677ef465ca214066c1b1 | |
parent | bc309d84d77a5719a332f2dffdf24006d8610f97 (diff) | |
download | qtlocation-mapboxgl-4479f5db6c1ce26bc187a1b5a938f4bdb45915d4.tar.gz |
[core] don't consult cache for asset resources
-rw-r--r-- | platform/default/online_file_source.cpp | 4 | ||||
-rw-r--r-- | test/storage/file_reading.cpp | 42 |
2 files changed, 44 insertions, 2 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index c482d6d96f..37ac3e9838 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -232,7 +232,7 @@ void OnlineFileSource::Impl::update(OnlineFileRequestImpl& request) { } else if (!request.cacheRequest && !request.realRequest) { // There is no request in progress, and we don't have a response yet. This means we'll have // to start the request ourselves. - if (cache) { + if (cache && !util::isAssetURL(request.resource.url)) { startCacheRequest(request); } else { startRealRequest(request); @@ -276,7 +276,7 @@ void OnlineFileSource::Impl::startRealRequest(OnlineFileRequestImpl& request) { auto callback = [this, &request](std::shared_ptr<const Response> response) { request.realRequest = nullptr; - if (cache) { + if (cache && !util::isAssetURL(request.resource.url)) { // Store response in database. Make sure we only refresh the expires column if the data // didn't change. FileCache::Hint hint = FileCache::Hint::Full; diff --git a/test/storage/file_reading.cpp b/test/storage/file_reading.cpp index 757decb612..a8ddd5a661 100644 --- a/test/storage/file_reading.cpp +++ b/test/storage/file_reading.cpp @@ -1,6 +1,7 @@ #include "storage.hpp" #include <mbgl/storage/online_file_source.hpp> +#include <mbgl/storage/sqlite_cache.hpp> #include <mbgl/platform/platform.hpp> #include <mbgl/util/chrono.hpp> #include <mbgl/util/run_loop.hpp> @@ -171,3 +172,44 @@ TEST_F(Storage, AssetNonExistentFile) { loop.run(); } + +TEST_F(Storage, AssetNotCached) { + SCOPED_TEST(NotCached) + + using namespace mbgl; + + const Resource resource { Resource::Unknown, "asset://TEST_DATA/fixtures/storage/nonempty" }; + + util::RunLoop loop; + + SQLiteCache cache(":memory:"); + + // Add a fake response to the cache to verify that we don't retrieve it. + { + auto response = std::make_shared<Response>(); + response->data = std::make_shared<const std::string>("cached data"); + cache.put(resource, response, FileCache::Hint::Full); + } + + OnlineFileSource fs(&cache, getFileSourceRoot()); + + std::unique_ptr<WorkRequest> workReq; + std::unique_ptr<FileRequest> req = fs.request(resource, [&](Response res) { + req.reset(); + + EXPECT_EQ(nullptr, res.error); + ASSERT_TRUE(res.data.get()); + EXPECT_EQ("content is here\n", *res.data); + + workReq = cache.get(resource, [&](std::shared_ptr<Response> response) { + // Check that we didn't put the file into the cache + ASSERT_TRUE(response->data.get()); + EXPECT_EQ(*response->data, "cached data"); + + loop.stop(); + NotCached.finish(); + }); + }); + + loop.run(); +} |