Skip to content

Commit

Permalink
Fix chrome cache
Browse files Browse the repository at this point in the history
  • Loading branch information
PanSpagetka committed Jan 30, 2020
1 parent c92f65a commit 61e6fc2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import NoAccess from './App/NoAccess';

const log = require('./jwt/logger')('entry.js');
const sourceOfTruth = require('./nav/sourceOfTruth');

// used for translating event names exposed publicly to internal event names
const PUBLIC_EVENTS = {
APP_NAVIGATION: fn => ({
Expand Down
15 changes: 13 additions & 2 deletions src/js/jwt/insights/entitlements.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
const axios = require('axios');
const { ServicesApi } = require('@redhat-cloud-services/entitlements-client');
const { bootstrapCache } = require('../../utils');
const { deleteLocalStorageItems, bootstrapCache, lastActive } = require('../../utils');

const BASE_PATH = '/api/entitlements/v1';

module.exports = (cachePrefix) => {
const cache = bootstrapCache(BASE_PATH, `${cachePrefix}-entitlements`);

const instance = axios.create({ adapter: cache.adapter });
instance.interceptors.response.use((response) => response.data || response);
instance.interceptors.response.use((response) => {

if (response && response.request && response.request.fromCache !== true) {
const last = lastActive('/api/entitlements/v1/services', 'fallback');
const keys = Object.keys(localStorage).filter(key => key.endsWith('/api/entitlements/v1/services') && key !== last);

deleteLocalStorageItems(keys);

}

return response.data || response;
});
return new ServicesApi(undefined, BASE_PATH, instance);
};
13 changes: 11 additions & 2 deletions src/js/nav/sourceOfTruth.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
const axios = require('axios');
const { bootstrapCache } = require('../utils');
const { deleteLocalStorageItems, bootstrapCache, lastActive } = require('../utils');
const c = console;

// Gets the source of truth from the CS Config repository, and caches it for 10 minutes.
module.exports = (cachePrefix) => {
const cache = bootstrapCache('/config/main.yml', `${cachePrefix}-nav`);

const instance = axios.create({ adapter: cache.adapter });
instance.interceptors.response.use((response) => {

instance.interceptors.response.use((response) => response.data || response);
if (response && response.request && response.request.fromCache !== true) {
const last = lastActive('/config/main.yml', 'fallback');
const keys = Object.keys(localStorage).filter(key => key.endsWith('config/main.yml') && key !== last);
localStorage.setItem('test', keys.length);
deleteLocalStorageItems(keys);
}

return response.data || response;
});
// Add prefix (/beta) depending on environment
let prefix = '';
if (window.location.pathname.indexOf('/beta') !== -1) {
Expand Down

0 comments on commit 61e6fc2

Please sign in to comment.