Usecase:
I have a specific use-case, where I have to load signed URL from Cloudfront very frequently. Signed Cloudfront URL looks something like this:
<base_url>/<filepath>?Expires=1692731643&Signature=sT-BagXsZkUnw....
Since this image file is accessed very frequently in the app, I wanted to cache it in the disk with some custom key(like <base_url>/<filepath>
since only GET parameters changes everytime. Can you please let me know how do I do this?
Things I tried:
This is how I have defined ImageLoader:
ImageLoader.Builder(this)
.diskCache {
DiskCache.Builder()
.directory(this.cacheDir.resolve("image_cache"))
.maxSizeBytes(2L * 1024 * 1024 * 1024) // 2 GB
.build()
}
.memoryCachePolicy(CachePolicy.ENABLED)
.diskCachePolicy(CachePolicy.ENABLED)
.crossfade(true)
.build()
This is how I have defined ImageRequest:
val cachedImageURL = url.split("?").first()
return ImageRequest.Builder(ctx)
.data(url)
.memoryCacheKey(cachedImageURL)
.diskCacheKey(cachedImageURL)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.something_went_wrong)
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.crossfade(true)
.build()