diff --git a/frontend/scenes/Dashboard/DashboardStore.js b/frontend/scenes/Dashboard/DashboardStore.js index 67c04c7d..aaf67601 100644 --- a/frontend/scenes/Dashboard/DashboardStore.js +++ b/frontend/scenes/Dashboard/DashboardStore.js @@ -1,5 +1,5 @@ import { observable, action, runInAction } from 'mobx'; -import { client, cacheResponse } from 'utils/ApiClient'; +import { client } from 'utils/ApiClient'; class DashboardStore { @observable collections; @@ -18,7 +18,6 @@ class DashboardStore { runInAction('fetchCollections', () => { this.collections = data; this.pagination = pagination; - data.forEach(collection => cacheResponse(collection.recentDocuments)); }); // If only one collection, visit it automatically diff --git a/frontend/scenes/DocumentScene/DocumentScene.js b/frontend/scenes/DocumentScene/DocumentScene.js index 05986db2..96daed9e 100644 --- a/frontend/scenes/DocumentScene/DocumentScene.js +++ b/frontend/scenes/DocumentScene/DocumentScene.js @@ -20,12 +20,11 @@ import styles from './DocumentScene.scss'; // const cx = classNames.bind(styles); @keydown(['cmd+/', 'ctrl+/', 'c', 'e']) -@inject('ui', 'cache') +@inject('ui') @observer class DocumentScene extends React.Component { static propTypes = { ui: PropTypes.object.isRequired, - cache: PropTypes.object.isRequired, routeParams: PropTypes.object, params: PropTypes.object.isRequired, location: PropTypes.object.isRequired, @@ -34,10 +33,7 @@ class DocumentScene extends React.Component { constructor(props) { super(props); this.store = new DocumentSceneStore( - JSON.parse(localStorage[DOCUMENT_PREFERENCES] || '{}'), - { - cache: this.props.cache, - } + JSON.parse(localStorage[DOCUMENT_PREFERENCES] || '{}') ); } diff --git a/frontend/scenes/DocumentScene/DocumentSceneStore.js b/frontend/scenes/DocumentScene/DocumentSceneStore.js index 60667b24..220cd02f 100644 --- a/frontend/scenes/DocumentScene/DocumentSceneStore.js +++ b/frontend/scenes/DocumentScene/DocumentSceneStore.js @@ -13,8 +13,6 @@ import { browserHistory } from 'react-router'; const DOCUMENT_PREFERENCES = 'DOCUMENT_PREFERENCES'; class DocumentSceneStore { - static cache; - @observable document; @observable collapsedNodes = []; @@ -53,18 +51,12 @@ class DocumentSceneStore { replaceUrl: true, ...options, }; - let cacheHit = false; - runInAction('retrieve document from cache', () => { - const cachedValue = this.cache.fetchFromCache(id); - cacheHit = !!cachedValue; - if (cacheHit) this.document = cachedValue; - }); this.isFetching = !options.softLoad; - this.updatingContent = options.softLoad && !cacheHit; + this.updatingContent = true; try { - const res = await client.get('/documents.info', { id }, { cache: true }); + const res = await client.get('/documents.info', { id }); const { data } = res; runInAction('fetchDocument', () => { this.document = data; @@ -131,7 +123,6 @@ class DocumentSceneStore { constructor(settings, options) { // Rehydrate settings this.collapsedNodes = settings.collapsedNodes || []; - this.cache = options.cache; // Persist settings to localStorage // TODO: This could be done more selectively diff --git a/frontend/stores/CacheStore.js b/frontend/stores/CacheStore.js deleted file mode 100644 index 077022bf..00000000 --- a/frontend/stores/CacheStore.js +++ /dev/null @@ -1,40 +0,0 @@ -import _ from 'lodash'; -import { action, toJS } from 'mobx'; - -const CACHE_STORE = 'CACHE_STORE'; - -class CacheStore { - cache = {}; - - /* Computed */ - - get asJson() { - return JSON.stringify({ - cache: this.cache, - }); - } - - /* Actions */ - - @action cacheWithId = (id, data) => { - this.cache[id] = toJS(data); - _.defer(() => localStorage.setItem(CACHE_STORE, this.asJson)); - }; - - @action cacheList = data => { - data.forEach(item => this.cacheWithId(item.id, item)); - }; - - @action fetchFromCache = id => { - return this.cache[id]; - }; - - constructor() { - // Rehydrate - const data = JSON.parse(localStorage.getItem(CACHE_STORE) || '{}'); - this.cache = data.cache || {}; - } -} - -export default CacheStore; -export { CACHE_STORE }; diff --git a/frontend/stores/index.js b/frontend/stores/index.js index ab1e9cc9..da9e3a51 100644 --- a/frontend/stores/index.js +++ b/frontend/stores/index.js @@ -1,12 +1,10 @@ import UserStore, { USER_STORE } from './UserStore'; import UiStore, { UI_STORE } from './UiStore'; -import CacheStore from './CacheStore'; import { autorunAsync } from 'mobx'; const stores = { user: new UserStore(), ui: new UiStore(), - cache: new CacheStore(), }; // Persist stores to localStorage diff --git a/frontend/utils/ApiClient.js b/frontend/utils/ApiClient.js index cff69215..368206c9 100644 --- a/frontend/utils/ApiClient.js +++ b/frontend/utils/ApiClient.js @@ -3,17 +3,6 @@ import { browserHistory } from 'react-router'; import constants from '../constants'; import stores from 'stores'; -const isIterable = object => - object != null && typeof object[Symbol.iterator] === 'function'; - -const cacheResponse = data => { - if (isIterable(data)) { - stores.cache.cacheList(data); - } else { - stores.cache.cacheWithId(data.id, data); - } -}; - class ApiClient { constructor(options = {}) { this.baseUrl = options.baseUrl || constants.API_BASE_URL; @@ -76,10 +65,6 @@ class ApiClient { return response.json(); }) .then(json => { - // Cache responses - if (options.cache) { - cacheResponse(json.data); - } resolve(json); }) .catch(error => { @@ -112,4 +97,4 @@ export default ApiClient; // In case you don't want to always initiate, just import with `import { client } ...` const client = new ApiClient(); -export { client, cacheResponse }; +export { client };