Skip to content

Commit

Permalink
Solution to problem with cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ignapas authored Oct 31, 2019
1 parent 2880c38 commit 0513c82
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions services/web/client/source/class/osparc/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ qx.Class.define("osparc.Application", {
if (isLogged) {
this.__loadMainPage();
} else {
// Reset store (cache)
osparc.store.Store.getInstance().invalidate();

osparc.auth.Manager.getInstance().validateToken(data => {
if (data.role === "Guest") {
// Logout a guest trying to access the Dashboard
Expand Down
35 changes: 35 additions & 0 deletions services/web/client/source/class/osparc/store/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
* <pre class='javascript'>
* let studies = osparc.store.Store.getInstance().getStudies();
* </pre>
*
* To invalidate the cache for any of the entities, config for example, just do:
* <pre class="javascript">
* osparc.store.Store.getInstance().resetConfig();
* </pre>
* or
* <pre class="javascript">
* osparc.store.Store.getInstance().invalidate("config");
* </pre>
* To invalidate the entire cache:
* <pre class="javascript">
* osparc.store.Store.getInstance().invalidate();
* </pre>
*/
qx.Class.define("osparc.store.Store", {
extend: qx.core.Object,
Expand Down Expand Up @@ -151,6 +164,28 @@ qx.Class.define("osparc.store.Store", {
return null;
}
return osparc.utils.Services.servicesCached;
},

/**
* Invalidates the cache for the given resources.
* If resource is a string, it will invalidate that resource.
* If it is an array, it will try to invalidate every resource in the array.
* If it is not provided, it will invalidate all resources.
*
* @param {(string|string[])} [resources] Property or array of property names that must be reset
*/
invalidate: function(resources) {
if (typeof resources === "string" || resources instanceof String) {
this.reset(resources);
} else {
let propertyArray;
if (resources == null) { // eslint-disable-line no-eq-null
propertyArray = Object.keys(qx.util.PropertyUtil.getProperties(osparc.store.Store));
} else if (Array.isArray(resources)) {
propertyArray = resources;
}
propertyArray.map(propName => this.reset(propName));
}
}
}
});

0 comments on commit 0513c82

Please sign in to comment.