Skip to content

Commit

Permalink
wip: cache miss
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Mar 22, 2021
1 parent 5bf90ee commit fedd9ca
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import { isDevMode } from '/@/utils/env';
// Register global components
registerGlobComp(app);

// Multilingual configuration
await setupI18n(app);

// Configure routing
setupRouter(app);

Expand All @@ -45,7 +48,7 @@ import { isDevMode } from '/@/utils/env';
setupErrorHandle(app);

// Mount when the route is ready
await Promise.all([setupI18n(app), router.isReady()]);
await router.isReady();

app.mount('#app', true);

Expand Down
2 changes: 1 addition & 1 deletion src/settings/projectSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const setting: ProjectConfig = {
permissionMode: PermissionModeEnum.ROLE,

// Permission-related cache is stored in sessionStorage or localStorage
permissionCacheType: CacheTypeEnum.SESSION,
permissionCacheType: CacheTypeEnum.LOCAL,

// color
themeColor: primaryColor,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export function getAuthCache<T>(key: BasicKeys) {

export function setAuthCache(key: BasicKeys, value) {
const fn = isLocal ? Persistent.setLocal : Persistent.setSession;
return fn(key, value);
return fn(key, value, true);
}
2 changes: 1 addition & 1 deletion src/utils/cache/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Memory<T = any, V = any> {
}
item.time = new Date().getTime() + this.alive;
item.timeoutId = setTimeout(() => {
this.remove(key);
// this.remove(key);
}, expires);

return value;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/cache/persistent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Persistent {

static setSession(key: SessionKeys, value: SessionStore[SessionKeys], immediate = false): void {
sessionMemory.set(key, toRaw(value));
immediate && ss.set(APP_SESSION_CACHE_KEY, sessionMemory);
immediate && ss.set(APP_SESSION_CACHE_KEY, sessionMemory.getCache);
}

static removeSession(key: SessionKeys): void {
Expand Down

3 comments on commit fedd9ca

@glorydreamtop
Copy link

@glorydreamtop glorydreamtop commented on fedd9ca Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个问题出在expires上,因为if (!expires || (expires as number) <= 0) { expires = this.alive; },这行没明白,你这里alive是个时间戳了,超过了setTimeout的最大安全值就无效,被成立即执行了。
你把remove这行注释掉,已经违背了原本的意义了,原本这意思是要在有效期结束后清除掉这份cache

@i7eo
Copy link

@i7eo i7eo commented on fedd9ca Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,目前项目开发中遇到了这样的问题。settimeout 超过 2^31 - 1 秒后立即执行,建议这里加上一天的判断,超过一天刷新一下吧。。。

@shawnxiao94
Copy link

@shawnxiao94 shawnxiao94 commented on fedd9ca Dec 7, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.