我正在开发一个应用程序,使用Coil compose图像加载器来显示私有图像列表。Coil默认启用图像缓存,或者我们也可以控制不需要凭据的图像URL的缓存策略。如何为私有图像URL进行图像缓存。以下是我的示例:
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data("${BuildConfig.BASE_URL}/.preview/avatar.jpg")
.addHeader("Authorization", "Token something")
.crossfade(true)
.diskCachePolicy(CachePolicy.ENABLED)// it's the same even removing comments
.build(),
placeholder = painterResource(R.drawable.ic_avatar),
contentDescription = stringResource(R.string.app_name),
contentScale = ContentScale.Crop,
modifier = Modifier.clip(CircleShape)
)
然而,如果不需要凭证,图像缓存适用于公共图像url。如果有人遇到这个问题并解决了它,我将非常感激你的帮助!