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 ~ScriptUser() =
default;
28 virtual void scriptContentsAvailable(
const QUrl& url,
const QString& scriptContents) = 0;
29 virtual void errorInLoadingScript(
const QUrl& url) = 0;
34 static const int MAX_RETRIES { 5 };
35 static const int START_DELAY_BETWEEN_RETRIES { 200 };
36 std::vector<contentAvailableCallback> scriptUsers { };
38 int maxRetries { MAX_RETRIES };
46 using Mutex = std::mutex;
47 using Lock = std::unique_lock<Mutex>;
50 static const QString STATUS_INLINE;
51 static const QString STATUS_CACHED;
52 static bool isSuccessStatus(
const QString& status) {
53 return status ==
"Success" || status == STATUS_INLINE || status == STATUS_CACHED;
57 Q_INVOKABLE
void clearATPScriptsFromCache();
58 void getScriptContents(
const QString& scriptOrURL, contentAvailableCallback contentAvailable,
bool forceDownload =
false,
int maxRetries = ScriptRequest::MAX_RETRIES);
60 void deleteScript(
const QUrl& unnormalizedURL);
63 void scriptContentAvailable(
int maxRetries);
67 QMap<QUrl, ScriptRequest> _activeScriptRequests;
69 QHash<QUrl, QVariantMap> _scriptCache;
70 QMultiMap<QUrl, ScriptUser*> _scriptUsers;
Dependency for for loading and caching scripts.
Definition: ScriptCache.h:42