getCacheKey method
获取缓存Key,customCacheKey和options必须有一个不为空,否则返回null
Implementation
String? getCacheKey(String? customCacheKey, RequestOptions? options) {
if (customCacheKey != null) {
return md5.convert(utf8.encode(customCacheKey)).toString();
}
if (options == null) {
return null;
}
String path = options.uri.toString();
customCacheKey = options.extra[CacheStrategy.CUSTOM_CACHE_KEY];
StringBuffer stringBuffer = StringBuffer(path);
options.queryParameters.forEach((key, value) {
stringBuffer.write("_");
stringBuffer.write(key);
stringBuffer.write("_");
stringBuffer.write(value);
});
var body = options.data;
if (body != null) {
stringBuffer.write("_");
stringBuffer.write(
md5.convert(utf8.encode(jsonEncode(body).toString())).toString(),
);
}
return md5.convert(utf8.encode(stringBuffer.toString())).toString();
}