Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chrome cache #512

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 18 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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);
};
12 changes: 10 additions & 2 deletions src/js/nav/sourceOfTruth.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
const axios = require('axios');
const { bootstrapCache } = require('../utils');
const { deleteLocalStorageItems, bootstrapCache, lastActive } = require('../utils');

// 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