From f9ccbc46ae7d20534b9cdf6ea19ed97173972b1d Mon Sep 17 00:00:00 2001 From: xmcp Date: Fri, 10 Jan 2020 21:28:04 +0800 Subject: [PATCH] add comment cache clear --- src/Title.js | 2 ++ src/cache.js | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Title.js b/src/Title.js index 253121d..916e34a 100644 --- a/src/Title.js +++ b/src/Title.js @@ -7,6 +7,7 @@ import {ConfigUI} from './Config'; import './Title.css'; import {BalanceShower} from './BalanceShower'; +import {cache} from './cache'; const flag_re=/^\/\/setflag ([a-zA-Z0-9_]+)=(.*)$/; @@ -36,6 +37,7 @@ const HELP_TEXT=( } }); } + cache().clear(); setTimeout(()=>{ window.location.reload(true); },200); diff --git a/src/cache.js b/src/cache.js index c8debe7..2e92c16 100644 --- a/src/cache.js +++ b/src/cache.js @@ -1,3 +1,4 @@ +const HOLE_CACHE_DB_NAME='hole_cache_db'; const CACHE_DB_VER=1; const MAINTENANCE_STEP=500; const MAINTENANCE_COUNT=5000; @@ -6,7 +7,7 @@ class Cache { constructor() { this.db=null; this.added_items_since_maintenance=0; - const open_req=indexedDB.open('hole_cache_db',CACHE_DB_VER); + const open_req=indexedDB.open(HOLE_CACHE_DB_NAME,CACHE_DB_VER); open_req.onerror=console.error.bind(console); open_req.onupgradeneeded=(event)=>{ console.log('comment cache db upgrade'); @@ -93,6 +94,13 @@ class Cache { }; count_req.onerror=console.error.bind(console); } + + clear() { + if(!this.db) + return; + indexedDB.deleteDatabase(HOLE_CACHE_DB_NAME); + console.log('delete comment cache db'); + } }; export function cache() {