getString method
获取有效数据
cacheKey
缓存key
Implementation
Future<String> getString({required String cacheKey}) async {
var value = await MmkvUtils.instance.getString(cacheKey);
if (value.isEmptyString || value.isEmptyJson) {
return "";
}
var map = value.jsonToMap;
if (!map.containsKey("startTime") || !map.containsKey("duration") || !map.containsKey("value")) {
return "";
}
if (map["value"] is! String) {
return "";
}
var content = map["value"] as String;
if ((map["startTime"] is! int) || (map["duration"] is! int)) {
return content;
}
var startTime = map["startTime"] as int;
var duration = map["duration"] as int;
if (startTime.isNullOrZero || duration.isNullOrZero) {
return content;
}
var diff = System.currentTimeMillis - startTime;
if (diff > duration) {
MmkvUtils.instance.remove(cacheKey);
return "";
}
return content;
}