summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-13 16:55:44 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-01-14 13:46:03 -0800
commit0066637e58ab47c7c1c9dcec123ff850ae33f8fc (patch)
tree7217384d6b51a05add8724aa93420a429f37f105 /platform
parent1c887ff728d85d75f77556452386a5ef70eee94f (diff)
downloadqtlocation-mapboxgl-0066637e58ab47c7c1c9dcec123ff850ae33f8fc.tar.gz
[core] Let SQLiteCache decide when store or refresh responses
Diffstat (limited to 'platform')
-rw-r--r--platform/default/online_file_source.cpp11
-rw-r--r--platform/default/sqlite_cache.cpp16
2 files changed, 11 insertions, 16 deletions
diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp
index 657871b907..a470a83462 100644
--- a/platform/default/online_file_source.cpp
+++ b/platform/default/online_file_source.cpp
@@ -244,15 +244,8 @@ void OnlineFileRequestImpl::scheduleRealRequest(OnlineFileSource::Impl& impl, bo
realRequest = impl.httpContext->createRequest(resource.url, [this, &impl](std::shared_ptr<const Response> response_) {
realRequest = nullptr;
- // Only update the cache for successful or 404 responses.
- // In particular, we don't want to write a Canceled request, or one that failed due to
- // connection errors to the cache. Server errors are hopefully also temporary, so we're not
- // caching them either.
- if (impl.cache &&
- (!response_->error || (response_->error->reason == Response::Error::Reason::NotFound))) {
- // Store response in database. Make sure we only refresh the expires column if the data
- // didn't change.
- impl.cache->put(resource, *response_, response_->notModified ? SQLiteCache::Hint::Refresh : SQLiteCache::Hint::Full);
+ if (impl.cache) {
+ impl.cache->put(resource, *response_);
}
response = response_;
diff --git a/platform/default/sqlite_cache.cpp b/platform/default/sqlite_cache.cpp
index 53f2c10c23..444637b9af 100644
--- a/platform/default/sqlite_cache.cpp
+++ b/platform/default/sqlite_cache.cpp
@@ -367,14 +367,16 @@ void SQLiteCache::Impl::get(const Resource &resource, Callback callback) {
}
}
-void SQLiteCache::put(const Resource &resource, const Response& response, Hint hint) {
- // Can be called from any thread, but most likely from the file source thread. We are either
- // storing a new response or updating the currently stored response, potentially setting a new
- // expiry date.
- if (hint == Hint::Full) {
- thread->invoke(&Impl::put, resource, response);
- } else if (hint == Hint::Refresh) {
+void SQLiteCache::put(const Resource& resource, const Response& response) {
+ // Except for 404s, don't store errors in the cache.
+ if (response.error && response.error->reason != Response::Error::Reason::NotFound) {
+ return;
+ }
+
+ if (response.notModified) {
thread->invoke(&Impl::refresh, resource, response.expires);
+ } else {
+ thread->invoke(&Impl::put, resource, response);
}
}