[core] don't consult cache for asset resources
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user