mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 08:36:42 +00:00
added cache warming on startup
This commit is contained in:
parent
2df5527cc0
commit
bfea4dbf5f
@ -74,9 +74,9 @@ function restoreUiAfterNaClLoad() {
|
||||
}
|
||||
|
||||
function beginBackgroundPollingOfHost(host) {
|
||||
host.warmBoxArtCache();
|
||||
if (host.online) {
|
||||
$("#hostgrid-" + host.serverUid).removeClass('host-cell-inactive');
|
||||
|
||||
// The host was already online. Just start polling in the background now.
|
||||
activePolls[host.serverUid] = window.setInterval(function() {
|
||||
// every 5 seconds, poll at the address we know it was live at
|
||||
@ -90,7 +90,6 @@ function beginBackgroundPollingOfHost(host) {
|
||||
}, 5000);
|
||||
} else {
|
||||
$("#hostgrid-" + host.serverUid).addClass('host-cell-inactive');
|
||||
|
||||
// The host was offline, so poll immediately.
|
||||
host.pollServer(function () {
|
||||
if (host.online) {
|
||||
|
@ -293,12 +293,35 @@ NvHTTP.prototype = {
|
||||
|
||||
return this.getAppListWithCacheFlush();
|
||||
},
|
||||
|
||||
warmBoxArtCache: function () {
|
||||
if (Object.keys(this._memCachedBoxArtArray).length != 0) {
|
||||
console.log('box art cache already warmed.');
|
||||
return;
|
||||
}
|
||||
if (chrome.storage) {
|
||||
chrome.storage.local.get('boxArtCache', function(JSONCachedBoxArtArray) {
|
||||
|
||||
var storedBoxArtArray; // load cached data if it exists
|
||||
if (JSONCachedBoxArtArray.boxArtCache != undefined) {
|
||||
storedBoxArtArray = JSONCachedBoxArtArray.boxArtCache;
|
||||
for (var key in storedBoxArtArray) {
|
||||
this._memCachedBoxArtArray[key] = _base64ToArrayBuffer(storedBoxArtArray[key]);
|
||||
}
|
||||
console.log('box art cache warmed.');
|
||||
} else {
|
||||
console.log('WARN: no box art found in storage. Cannot warm cache!');
|
||||
return;
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
// returns the box art of the given appID.
|
||||
// three layers of response time are possible: memory cached (in javascript), storage cached (in chrome.storage.local), and streamed (host sends binary over the network)
|
||||
getBoxArt: function (appId) {
|
||||
|
||||
// TODO: unfortunately we do N lookups from storage cache, each of them filling up the memory cache.
|
||||
// TODO: unfortunately we do N lookups from storage cache, each of them filling up the memory cache.
|
||||
// once the first round of calls are all made, each subsequent request hits this and returns from memory cache
|
||||
if (this._memCachedBoxArtArray[appId] !== undefined) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user