Commit c620f8279f1056ddab84b3907fb50b3af4fe9247

Authored by vben
1 parent b350098f

perf: set cache default time

CHANGELOG.zh_CN.md
... ... @@ -15,6 +15,7 @@
15 15 ### ⚡ Performance Improvements
16 16  
17 17 - `setTitle`逻辑调整
  18 +- 将系统用到的 sessionStorage 及 LocalStorage 缓存设置默认 `7` 天过期
18 19  
19 20 ### ✨ Refactor
20 21  
... ...
src/settings/cipherSetting.ts
  1 +// System default cache time, in seconds
  2 +export const DEFAULT_CACHE_TIME = 60 * 60 * 24 * 7;
  3 +
1 4 /**
2 5 * @description:
3 6 */
... ...
src/utils/helper/persistent.ts
... ... @@ -6,10 +6,15 @@ import { BASE_LOCAL_CACHE_KEY, BASE_SESSION_CACHE_KEY } from '/@/enums/cacheEnum
6 6 const ls = createStorage(localStorage);
7 7 const ss = createStorage();
8 8  
  9 +interface CacheStore {
  10 + local?: any;
  11 + session?: any;
  12 +}
  13 +
9 14 /**
10 15 * @description: Persistent cache
11 16 */
12   -const cacheStore: any = {
  17 +const cacheStore: CacheStore = {
13 18 // localstorage cache
14 19 local: {},
15 20 // sessionstorage cache
... ...
src/utils/storage/Storage.ts
1   -import { EncryptionParams } from '/@/utils/cipher/aesEncryption';
2   -export interface CreateStorageParams extends EncryptionParams {
  1 +import { DEFAULT_CACHE_TIME } from '/@/settings/cipherSetting';
  2 +
  3 +// import { EncryptionParams } from '/@/utils/cipher/aesEncryption';
  4 +export interface CreateStorageParams {
3 5 storage: Storage;
4 6 hasEncrypt: boolean;
5 7 }
6   -const defaultTime = 60 * 60 * 24 * 7;
7 8 export const createStorage = ({ prefixKey = '', storage = sessionStorage } = {}) => {
8 9 /**
9 10 *缓存类
... ... @@ -36,7 +37,7 @@ export const createStorage = ({ prefixKey = '', storage = sessionStorage } = {})
36 37 * @expire 过期时间 单位秒
37 38 * @memberof Cache
38 39 */
39   - set(key: string, value: any, expire: number | null = defaultTime) {
  40 + set(key: string, value: any, expire: number | null = DEFAULT_CACHE_TIME) {
40 41 const stringData = JSON.stringify({
41 42 value,
42 43 expire: expire !== null ? new Date().getTime() + expire * 1000 : null,
... ... @@ -96,7 +97,7 @@ export const createStorage = ({ prefixKey = '', storage = sessionStorage } = {})
96 97 * 例子:
97 98 * cookieData.set('name','value',)
98 99 */
99   - setCookie(name: string, value: any, expire: number | null = defaultTime) {
  100 + setCookie(name: string, value: any, expire: number | null = DEFAULT_CACHE_TIME) {
100 101 document.cookie = this.getKey(name) + '=' + value + '; Max-Age=' + expire;
101 102 }
102 103  
... ...