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 | Lock lock(_containerLock); | 86 | Lock lock(_containerLock); |
| 87 | if (_scriptCache.contains(url) && !forceDownload) { | 87 | if (_scriptCache.contains(url) && !forceDownload) { |
| 88 | auto scriptContent = _scriptCache[url]; | 88 | auto entry = _scriptCache[url]; |
| 89 | lock.unlock(); | 89 | if (url.isLocalFile() || url.scheme().isEmpty()) { |
| 90 | qCDebug(scriptengine) << "Found script in cache:" << url.fileName(); | 90 | auto mtime = QFileInfo(url.toLocalFile()).lastModified(); |
| 91 | contentAvailable(url.toString(), scriptContent, true, true, STATUS_CACHED); | 91 | QString localTime = ResourceRequest::toHttpDateString(mtime.toMSecsSinceEpoch()); |
| 92 | } else { | 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 | auto& scriptRequest = _activeScriptRequests[url]; | 107 | auto& scriptRequest = _activeScriptRequests[url]; |
| 94 | bool alreadyWaiting = scriptRequest.scriptUsers.size() > 0; | 108 | bool alreadyWaiting = scriptRequest.scriptUsers.size() > 0; |
| 95 | scriptRequest.scriptUsers.push_back(contentAvailable); | 109 | scriptRequest.scriptUsers.push_back(contentAvailable); |
| @@ -140,7 +154,10 @@ void ScriptCache::scriptContentAvailable(int maxRetries) { · 44 unmodified lines | |||
| 140 | 154 | ||
| 141 | _activeScriptRequests.remove(url); | 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 | } else { | 161 | } else { |
| 145 | auto result = req->getResult(); | 162 | auto result = req->getResult(); |
| 146 | bool irrecoverable = | 163 | bool irrecoverable = |
| @@ -177,7 +194,7 @@ void ScriptCache::scriptContentAvailable(int maxRetries) { · 30 unmodified lines | |||
| 177 | allCallbacks = scriptRequest.scriptUsers; | 194 | allCallbacks = scriptRequest.scriptUsers; |
| 178 | 195 | ||
| 179 | if (_scriptCache.contains(url)) { | 196 | if (_scriptCache.contains(url)) { |
| 180 | scriptContent = _scriptCache[url]; | 197 | scriptContent = _scriptCache[url]["data"].toString(); |
| 181 | } | 198 | } |
| 182 | _activeScriptRequests.remove(url); | 199 | _activeScriptRequests.remove(url); |
| 183 | qCWarning(scriptengine) << "Error loading script from URL (" << status <<")"; | 200 | qCWarning(scriptengine) << "Error loading script from URL (" << status <<")"; |