You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.2 KiB
72 lines
1.2 KiB
const writeGameCahce = (gameData) => {
|
|
gameData.isCache = true
|
|
uni.setStorageSync("cache", true);
|
|
uni.setStorageSync("cacheData", gameData);
|
|
console.log('保存game缓存成功')
|
|
}
|
|
|
|
const clearGameCache = (gameData) => {
|
|
if (gameData.isCache) {
|
|
uni.setStorageSync("cache", false);
|
|
uni.setStorageSync("cacheData", {});
|
|
console.log('清除game缓存成功')
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 使用读取时 最好 hasCache() 返回True 在进行调用
|
|
*/
|
|
const readGameCahce = () => {
|
|
|
|
let value
|
|
try {
|
|
value = uni.getStorageSync("cacheData");
|
|
if (value) {
|
|
console.log(value);
|
|
}
|
|
} catch (e) {
|
|
// error
|
|
value = null
|
|
console.log("error");
|
|
}
|
|
|
|
if (value == undefined || value == null || value === "" || value === "null") {
|
|
return {};
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
/**
|
|
* 是否有缓存
|
|
*/
|
|
const hasCache = () => {
|
|
|
|
let value
|
|
try {
|
|
value = uni.getStorageSync("cache");
|
|
if (value) {
|
|
console.log(value);
|
|
}
|
|
} catch (e) {
|
|
// error
|
|
value = null
|
|
console.log("error");
|
|
}
|
|
|
|
if (value == undefined || value == null || value === "" || value === "null") {
|
|
return false;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
export {
|
|
writeGameCahce,
|
|
clearGameCache,
|
|
readGameCahce,
|
|
hasCache
|
|
}
|
|
|