Vben
authored
|
1
|
import { Persistent, BasicKeys } from '/@/utils/cache/persistent';
|
vben
authored
|
2
|
import { CacheTypeEnum, TOKEN_KEY } from '/@/enums/cacheEnum';
|
Vben
authored
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import projectSetting from '/@/settings/projectSetting';
const { permissionCacheType } = projectSetting;
const isLocal = permissionCacheType === CacheTypeEnum.LOCAL;
export function getToken() {
return getAuthCache(TOKEN_KEY);
}
export function getAuthCache<T>(key: BasicKeys) {
const fn = isLocal ? Persistent.getLocal : Persistent.getSession;
return fn(key) as T;
}
export function setAuthCache(key: BasicKeys, value) {
const fn = isLocal ? Persistent.setLocal : Persistent.setSession;
|
Vben
authored
|
19
|
return fn(key, value, true);
|
Vben
authored
|
20
|
}
|
|
21
22
23
24
25
|
export function clearAuthCache(immediate = true) {
const fn = isLocal ? Persistent.clearLocal : Persistent.clearSession;
return fn(immediate);
}
|