Vben
authored
|
1
|
import { getStorageShortName } from '/@/utils/env';
|
Vben
authored
|
2
|
import { createStorage as create, CreateStorageParams } from './storageCache';
|
vben
authored
|
3
|
import { enableStorageEncryption, DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting';
|
|
4
|
|
Vben
authored
|
5
6
7
|
export type Options = Partial<CreateStorageParams>;
const createOptions = (storage: Storage, options: Options = {}): Options => {
|
|
8
|
return {
|
vben
authored
|
9
10
|
// No encryption in debug mode
hasEncrypt: enableStorageEncryption,
|
|
11
12
|
storage,
prefixKey: getStorageShortName(),
|
Vben
authored
|
13
|
...options,
|
|
14
15
|
};
};
|
vben
authored
|
16
|
|
Vben
authored
|
17
18
19
20
21
|
export const WebStorage = create(createOptions(sessionStorage));
export const createStorage = (storage: Storage = sessionStorage, options: Options = {}) => {
return create(createOptions(storage, options));
};
|
|
22
|
|
Vben
authored
|
23
24
25
26
27
28
|
export const createSessionStorage = (options: Options = {}) => {
return createStorage(sessionStorage, { ...options, timeout: DEFAULT_CACHE_TIME });
};
export const createLocalStorage = (options: Options = {}) => {
return createStorage(localStorage, { ...options, timeout: DEFAULT_CACHE_TIME });
|
|
29
|
};
|
vben
authored
|
30
|
|
|
31
|
export default WebStorage;
|