diff --git a/CHANGELOG.zh_CN.md b/CHANGELOG.zh_CN.md index 14fa81a70..8b97662e2 100644 --- a/CHANGELOG.zh_CN.md +++ b/CHANGELOG.zh_CN.md @@ -15,6 +15,7 @@ ### ⚡ Performance Improvements - `setTitle`逻辑调整 +- 将系统用到的 sessionStorage 及 LocalStorage 缓存设置默认 `7` 天过期 ### ✨ Refactor diff --git a/src/settings/cipherSetting.ts b/src/settings/cipherSetting.ts index 5809ea109..0b9e93c64 100644 --- a/src/settings/cipherSetting.ts +++ b/src/settings/cipherSetting.ts @@ -1,3 +1,6 @@ +// System default cache time, in seconds +export const DEFAULT_CACHE_TIME = 60 * 60 * 24 * 7; + /** * @description: */ diff --git a/src/utils/helper/persistent.ts b/src/utils/helper/persistent.ts index 3d8a8313e..0b5fef325 100644 --- a/src/utils/helper/persistent.ts +++ b/src/utils/helper/persistent.ts @@ -6,10 +6,15 @@ import { BASE_LOCAL_CACHE_KEY, BASE_SESSION_CACHE_KEY } from '/@/enums/cacheEnum const ls = createStorage(localStorage); const ss = createStorage(); +interface CacheStore { + local?: any; + session?: any; +} + /** * @description: Persistent cache */ -const cacheStore: any = { +const cacheStore: CacheStore = { // localstorage cache local: {}, // sessionstorage cache diff --git a/src/utils/storage/Storage.ts b/src/utils/storage/Storage.ts index d430465f0..57ab7a023 100644 --- a/src/utils/storage/Storage.ts +++ b/src/utils/storage/Storage.ts @@ -1,9 +1,10 @@ -import { EncryptionParams } from '/@/utils/cipher/aesEncryption'; -export interface CreateStorageParams extends EncryptionParams { +import { DEFAULT_CACHE_TIME } from '/@/settings/cipherSetting'; + +// import { EncryptionParams } from '/@/utils/cipher/aesEncryption'; +export interface CreateStorageParams { storage: Storage; hasEncrypt: boolean; } -const defaultTime = 60 * 60 * 24 * 7; export const createStorage = ({ prefixKey = '', storage = sessionStorage } = {}) => { /** *缓存类 @@ -36,7 +37,7 @@ export const createStorage = ({ prefixKey = '', storage = sessionStorage } = {}) * @expire 过期时间 单位秒 * @memberof Cache */ - set(key: string, value: any, expire: number | null = defaultTime) { + set(key: string, value: any, expire: number | null = DEFAULT_CACHE_TIME) { const stringData = JSON.stringify({ value, expire: expire !== null ? new Date().getTime() + expire * 1000 : null, @@ -96,7 +97,7 @@ export const createStorage = ({ prefixKey = '', storage = sessionStorage } = {}) * 例子: * cookieData.set('name','value',) */ - setCookie(name: string, value: any, expire: number | null = defaultTime) { + setCookie(name: string, value: any, expire: number | null = DEFAULT_CACHE_TIME) { document.cookie = this.getKey(name) + '=' + value + '; Max-Age=' + expire; }