This commit is contained in:
xmcp
2019-08-18 16:05:37 +08:00
parent a671a3c84f
commit f580f1b797
4 changed files with 11 additions and 13 deletions

View File

@@ -39,7 +39,7 @@ class Cache {
resolve(null);
} else if(target_version===res.version) { // hit
console.log('cache hit');
res.last_access=+new Date();
res.last_access=(+new Date());
store.put(res);
resolve(res.data);
} else { // expired
@@ -97,4 +97,8 @@ class Cache {
}
};
export let cache=new Cache();
export function cache() {
if(!window._cache)
window._cache=new Cache();
return window._cache;
}

View File

@@ -27,7 +27,7 @@ export const API={
else throw new Error(JSON.stringify(json));
}
cache.put(pid,cache_version,json);
cache().put(pid,cache_version,json);
// also change load_replies_with_cache!
json.data=json.data
@@ -46,7 +46,7 @@ export const API={
load_replies_with_cache: (pid,token,color_picker,cache_version)=> {
pid=parseInt(pid);
return cache.get(pid,cache_version)
return cache().get(pid,cache_version)
.then((json)=>{
if(json) {
// also change load_replies!

View File

@@ -2,16 +2,10 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
//import {elevate} from './infrastructure/elevator';
//import registerServiceWorker from './registerServiceWorker';
if(window.location.search.indexOf('user_token=')!==-1)
window.history.replaceState({},'?','?');
//elevate();
ReactDOM.render(<App />, document.getElementById('root'));
//registerServiceWorker();
if(navigator.serviceWorker && navigator.serviceWorker.getRegistrations)
navigator.serviceWorker.getRegistrations()
.then(function(registrations) {
for(let registration of registrations) {
registration.unregister();
}});