LsxCacheHelper.js 690 B

1234567891011121314151617181920212223242526
  1. export class LsxCacheHelper {
  2. static retrieveFromSessionStorage() {
  3. return JSON.parse(sessionStorage.getItem('lsx-cache')) || {};
  4. }
  5. static saveToSessionStorage(cacheObj) {
  6. sessionStorage.setItem('lsx-cache', JSON.stringify(cacheObj));
  7. }
  8. static generateCacheKeyFromContext(lsxContext) {
  9. return `${lsxContext.fromPagePath}__${lsxContext.lsxArgs}`;
  10. }
  11. static getStateCache(key) {
  12. let cacheObj = LsxCacheHelper.retrieveFromSessionStorage();
  13. return cacheObj[key];
  14. }
  15. static cacheState(key, lsxState) {
  16. let cacheObj = LsxCacheHelper.retrieveFromSessionStorage();
  17. cacheObj[key] = lsxState;
  18. LsxCacheHelper.saveToSessionStorage(cacheObj);
  19. }
  20. }