Showing the changes to libraries/script-engine/src/ScriptCache.cpp (1 of 3 files). Show all
Unified · Split
| @@ -85,11 +85,25 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 84 unmodified lines | ||
| 85 | 85 | |
| 86 | 86 | Lock lock(_containerLock); |
| 87 | 87 | if (_scriptCache.contains(url) && !forceDownload) { |
| 88 | − auto scriptContent = _scriptCache[url]; | |
| 89 | − lock.unlock(); | |
| 90 | − qCDebug(scriptengine) << "Found script in cache:" << url.fileName(); | |
| 91 | − contentAvailable(url.toString(), scriptContent, true, true, STATUS_CACHED); | |
| 92 | − } else { | |
| 88 | + auto entry = _scriptCache[url]; | |
| 89 | + if (url.isLocalFile() || url.scheme().isEmpty()) { | |
| 90 | + auto mtime = QFileInfo(url.toLocalFile()).lastModified(); | |
| 91 | + QString localTime = ResourceRequest::toHttpDateString(mtime.toMSecsSinceEpoch()); | |
| 92 | + QString cachedTime = entry["last-modified"].toString(); | |
| 93 | + if (cachedTime != localTime) { | |
| 94 | + forceDownload = true; | |
| 95 | + qCDebug(scriptengine) << "Found script in cache, but local file modified; reloading:" << url.fileName() | |
| 96 | + << "(memory:" << cachedTime << "disk:" << localTime << ")"; | |
| 97 | + } | |
| 98 | + } | |
| 99 | + if (!forceDownload) { | |
| 100 | + lock.unlock(); | |
| 101 | + qCDebug(scriptengine) << "Found script in cache:" << url.fileName(); | |
| 102 | + contentAvailable(url.toString(), entry["data"].toString(), true, true, STATUS_CACHED); | |
| 103 | + return; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + { | |
| 93 | 107 | auto& scriptRequest = _activeScriptRequests[url]; |
| 94 | 108 | bool alreadyWaiting = scriptRequest.scriptUsers.size() > 0; |
| 95 | 109 | scriptRequest.scriptUsers.push_back(contentAvailable); |
| @@ -140,7 +154,10 @@ void ScriptCache::scriptContentAvailable(int maxRetries) { · 44 unmodified lines | ||
| 140 | 154 | |
| 141 | 155 | _activeScriptRequests.remove(url); |
| 142 | 156 | |
| 143 | − _scriptCache[url] = scriptContent = req->getData(); | |
| 157 | + _scriptCache[url] = { | |
| 158 | + { "data", scriptContent = req->getData() }, | |
| 159 | + { "last-modified", req->property("last-modified") }, | |
| 160 | + }; | |
| 144 | 161 | } else { |
| 145 | 162 | auto result = req->getResult(); |
| 146 | 163 | bool irrecoverable = |
| @@ -177,7 +194,7 @@ void ScriptCache::scriptContentAvailable(int maxRetries) { · 30 unmodified lines | ||
| 177 | 194 | allCallbacks = scriptRequest.scriptUsers; |
| 178 | 195 | |
| 179 | 196 | if (_scriptCache.contains(url)) { |
| 180 | − scriptContent = _scriptCache[url]; | |
| 197 | + scriptContent = _scriptCache[url]["data"].toString(); | |
| 181 | 198 | } |
| 182 | 199 | _activeScriptRequests.remove(url); |
| 183 | 200 | qCWarning(scriptengine) << "Error loading script from URL (" << status <<")"; |