[core] Add Resource::StoragePolicy and consider it in resource loader
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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{});
|
||||
|
||||
Reference in New Issue
Block a user