From 4479f5db6c1ce26bc187a1b5a938f4bdb45915d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 8 Jan 2016 13:05:51 +0100 Subject: [PATCH] [core] don't consult cache for asset resources --- platform/default/online_file_source.cpp | 4 +-- 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 c482d6d96..37ac3e983 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 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 757decb61..a8ddd5a66 100644 --- a/test/storage/file_reading.cpp +++ b/test/storage/file_reading.cpp @@ -1,6 +1,7 @@ #include "storage.hpp" #include +#include #include #include #include @@ -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->data = std::make_shared("cached data"); + cache.put(resource, response, FileCache::Hint::Full); + } + + OnlineFileSource fs(&cache, getFileSourceRoot()); + + std::unique_ptr workReq; + std::unique_ptr 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) { + // 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(); +}