17 #ifndef hifi_ScriptCache_h
18 #define hifi_ScriptCache_h
21 #include <DependencyManager.h>
23 using contentAvailableCallback = std::function<void(
const QString& scriptOrURL,
const QString& contents,
bool isURL,
bool contentAvailable,
const QString& status)>;
27 virtual void scriptContentsAvailable(
const QUrl& url,
const QString& scriptContents) = 0;
28 virtual void errorInLoadingScript(
const QUrl& url) = 0;
33 static const int MAX_RETRIES { 5 };
34 static const int START_DELAY_BETWEEN_RETRIES { 200 };
35 std::vector<contentAvailableCallback> scriptUsers { };
37 int maxRetries { MAX_RETRIES };
45 using Mutex = std::mutex;
46 using Lock = std::unique_lock<Mutex>;
49 static const QString STATUS_INLINE;
50 static const QString STATUS_CACHED;
51 static bool isSuccessStatus(
const QString& status) {
52 return status ==
"Success" || status == STATUS_INLINE || status == STATUS_CACHED;
56 Q_INVOKABLE
void clearATPScriptsFromCache();
57 void getScriptContents(
const QString& scriptOrURL, contentAvailableCallback contentAvailable,
bool forceDownload =
false,
int maxRetries = ScriptRequest::MAX_RETRIES);
59 void deleteScript(
const QUrl& unnormalizedURL);
62 void scriptContentAvailable(
int maxRetries);
66 QMap<QUrl, ScriptRequest> _activeScriptRequests;
68 QHash<QUrl, QVariantMap> _scriptCache;
69 QMultiMap<QUrl, ScriptUser*> _scriptUsers;
Dependency for for loading and caching scripts.
Definition: ScriptCache.h:41