getCacheKeyFromPath static method
Implementation
static String getCacheKeyFromPath(String? path, Map<String, dynamic> params,List<String> ignoreKeys) {
String cacheKey = "";
if (!(TextUtil.isEmpty(path))) {
cacheKey = cacheKey + MD5Util.generateMd5(path!);
} else {
throw Exception("请求地址不能为空!");
}
if (params.isNotEmpty) {
final tempParams = Map<String,dynamic>.from(params);
tempParams.removeWhere((key, value) => ignoreKeys.contains(key));
String paramsStr = "";
// Sort keys for consistent cache key generation
List<String> sortedKeys = tempParams.keys.toList()..sort();
for (var key in sortedKeys) {
paramsStr = "$paramsStr$key${tempParams[key]}";
}
// tempParams.forEach((key, value) {
// paramsStr = "$paramsStr$key$value";
// });
if (paramsStr.isNotEmpty) {
cacheKey = cacheKey + MD5Util.generateMd5(paramsStr);
}
}
return cacheKey;
}