Skip to content

Commit

Permalink
Merge 7118762 into e4684e8
Browse files Browse the repository at this point in the history
  • Loading branch information
peuter committed Nov 16, 2018
2 parents e4684e8 + 7118762 commit cdd5fa8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/class/cv/Application.js
Expand Up @@ -547,7 +547,7 @@ qx.Class.define("cv.Application",
var startpage = 'id_';
if (cv.Config.startpage) {
startpage = cv.Config.startpage;
if (typeof(Storage) !== 'undefined') {
if (qx.core.Environment.get("html.storage.local") === true) {
if ('remember' === startpage) {
startpage = localStorage.getItem('lastpage');
cv.Config.rememberLastPage = true;
Expand Down
14 changes: 10 additions & 4 deletions source/class/cv/Config.js
Expand Up @@ -280,11 +280,17 @@ qx.Class.define('cv.Config', {
cv.Config.reporting = req.queryKey.reporting === 'true';
}

if (req.queryKey.enableCache === "invalid") {
cv.ConfigCache.clear(cv.Config.configSuffix);
cv.Config.enableCache = true;
// caching is only possible when localStorage is available
if (qx.core.Environment.get("html.storage.local") === false) {
cv.Config.enableCache = false;
console.warn('localStorage is not available in your browser. Some advanced features, like caching will not work!');
} else {
cv.Config.enableCache = req.queryKey.enableCache ? req.queryKey.enableCache === "true" : !qx.core.Environment.get("qx.debug");
if (req.queryKey.enableCache === "invalid") {
cv.ConfigCache.clear(cv.Config.configSuffix);
cv.Config.enableCache = true;
} else {
cv.Config.enableCache = req.queryKey.enableCache ? req.queryKey.enableCache === "true" : !qx.core.Environment.get("qx.debug");
}
}

cv.Config.enableLogging = qx.core.Environment.get("html.console");
Expand Down
22 changes: 21 additions & 1 deletion source/class/cv/ConfigCache.js
Expand Up @@ -38,6 +38,9 @@ qx.Class.define('cv.ConfigCache', {
_valid : null,

dump : function(xml) {
if (qx.core.Environment.get("html.storage.local") === false) {
return;
}
var config = qx.lang.Object.clone(cv.Config.configSettings, true);
var model = cv.data.Model.getInstance();
this.save(this._cacheKey, {
Expand All @@ -61,14 +64,22 @@ qx.Class.define('cv.ConfigCache', {
},

save: function(key, data) {
localStorage.setItem(cv.Config.configSuffix+"."+key, qx.lang.Json.stringify(data));
if (qx.core.Environment.get("html.storage.local") === true) {
localStorage.setItem(cv.Config.configSuffix + "." + key, qx.lang.Json.stringify(data));
}
},

getBody: function() {
if (qx.core.Environment.get("html.storage.local") === false) {
return null;
}
return localStorage.getItem(cv.Config.configSuffix + ".body");
},

getData: function(key) {
if (qx.core.Environment.get("html.storage.local") === false) {
return null;
}
if (!this._parseCacheData) {
this._parseCacheData = qx.lang.Json.parse(localStorage.getItem(cv.Config.configSuffix + "." + this._cacheKey));
}
Expand All @@ -86,6 +97,9 @@ qx.Class.define('cv.ConfigCache', {
* Returns true if there is an existing cache for the current config file
*/
isCached: function() {
if (qx.core.Environment.get("html.storage.local") === false) {
return false;
}
if (localStorage.getItem(cv.Config.configSuffix + "." + this._cacheKey) !== null) {
// compare versions
var cacheVersion = this.getData("VERSION");
Expand All @@ -97,6 +111,9 @@ qx.Class.define('cv.ConfigCache', {
},

isValid: function(xml) {
if (qx.core.Environment.get("html.storage.local") === false) {
return false;
}
// cache the result, as the config stays the same until next reload
if (this._valid === null) {
var hash = this.toHash(xml);
Expand All @@ -111,6 +128,9 @@ qx.Class.define('cv.ConfigCache', {
},

clear: function(configSuffix) {
if (qx.core.Environment.get("html.storage.local") === false) {
return;
}
configSuffix = configSuffix || cv.Config.configSuffix;
localStorage.removeItem(configSuffix+"."+this._cacheKey);
localStorage.removeItem(configSuffix+".body");
Expand Down
2 changes: 1 addition & 1 deletion source/class/cv/TemplateEngine.js
Expand Up @@ -695,7 +695,7 @@ qx.Class.define('cv.TemplateEngine', {
speed = cv.Config.configSettings.scrollSpeed;
}

if (cv.Config.rememberLastPage) {
if (cv.Config.rememberLastPage && qx.core.Environment.get("html.storage.local")) {
localStorage.lastpage = page_id;
}

Expand Down
2 changes: 1 addition & 1 deletion source/class/cv/report/Replay.js
Expand Up @@ -100,7 +100,7 @@ qx.Class.define('cv.report.Replay', {
this.__log = log.log;
this.__data = log.data;
this.__config = qx.xml.Document.fromString(log.config);
if (log.data.cache) {
if (log.data.cache && qx.core.Environment.get("html.storage.local") === true) {
localStorage.setItem(cv.Config.configSuffix + ".body", log.data.cache.body);
localStorage.setItem(cv.Config.configSuffix + ".data", qx.lang.Json.stringify(log.data.cache.data));
}
Expand Down

0 comments on commit cdd5fa8

Please sign in to comment.