init: 初始系统模板
This commit is contained in:
40
src/utils/cache-local-utils.ts
Normal file
40
src/utils/cache-local-utils.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**长期级缓存设置 */
|
||||
export function localSet(key: string, value: string) {
|
||||
if (!localStorage || key == null || value == null) {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
|
||||
/**长期级缓存获取 */
|
||||
export function localGet(key: string) {
|
||||
if (!localStorage || key == null) {
|
||||
return null;
|
||||
}
|
||||
return localStorage.getItem(key);
|
||||
}
|
||||
|
||||
/**长期级缓存移除 */
|
||||
export function localRemove(key: string) {
|
||||
if (!localStorage || key == null) {
|
||||
return null;
|
||||
}
|
||||
return localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
/**长期级缓存设置JSON */
|
||||
export function localSetJSON(key: string, jsonValue: object) {
|
||||
if (key == null || jsonValue == null) {
|
||||
return null;
|
||||
}
|
||||
localSet(key, JSON.stringify(jsonValue));
|
||||
}
|
||||
|
||||
/**长期级缓存获取JSON */
|
||||
export function localGetJSON(key: string) {
|
||||
const value = localGet(key);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parse(value);
|
||||
}
|
||||
Reference in New Issue
Block a user