QNetworkRequest ItemsManagerWorker::MakeCharacterRequest(const std::string &name, const ItemLocation &location) { QUrlQuery query; query.addQueryItem("character", name.c_str()); query.addQueryItem("accountName", account_name_.c_str()); QUrl url(kCharacterItemsUrl); url.setQuery(query); TabCache::Flags flags; if (!location.IsValid() || bo_manager_.GetRefreshChecked(location)) flags |= TabCache::Refresh; return Request(url, location, flags); }
QNetworkRequest ItemsManagerWorker::MakeTabRequest(int tab_index, const ItemLocation &location, bool tabs) { QUrlQuery query; query.addQueryItem("league", league_.c_str()); query.addQueryItem("tabs", tabs ? "1" : "0"); query.addQueryItem("tabIndex", QString::number(tab_index)); query.addQueryItem("accountName", account_name_.c_str()); QUrl url(kStashItemsUrl); url.setQuery(query); TabCache::Flags flags; if (tabs) flags |= TabCache::Refresh; if (!location.IsValid() || bo_manager_.GetRefreshChecked(location)) flags |= TabCache::Refresh; return Request(url, location, flags); }
QNetworkRequest TabCache::Request(const QUrl &url, const ItemLocation &location, Flags flags) { QNetworkRequest request{url}; // The cache policy exists so it can override normal behavior for a given refresh. // Based on the current policy we may ignore refresh requests, or force refreshes // even if none was specifed with 'flags'. switch (cache_policy_) { case DefaultCache: // This is the default policy, where we honor cache policy as specified by 'flags' // Evict this request from the cache if refresh is requested if (flags.testFlag(Refresh)) remove(url); break; case AlwaysCache: // By default we always try to hit in the cache, so this policy just allows // the normal cache mechanism to do its job and it will basically grab everything // from the cache that is available for all network requests break; case NeverCache: // We've already fully flushed the cache in OnPolicyUpdate, so nothing to do here. break; case ManualCache: // The case involves refreshing only an explicitily specified set of named tabs, customers // use AddManualRefresh to indicate what set of tabs to refresh before triggering a refresh // all other network requests will come from the cache if available if (location.IsValid() && manual_refresh_.count(location.GetUniqueHash())) remove(url); break; default: QLOG_ERROR() << "TabCache::Request Failed to handle all cache policy cases"; break; }; // At this point we've evicted any request that should be refreshed, so we always // tell the 'real' request to prefer but not require the entry be in the cache. // If it is not in the cache it will be fetched from the network regardless. request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, QNetworkRequest::PreferCache); return request; }
void TabCache::AddManualRefresh( const ItemLocation &location) { if (location.IsValid()) manual_refresh_.insert(location.GetUniqueHash()); }