With Glide Compose GlideImage composable function, how to enable disk caching

548 Views Asked by At

According to GlideImage documentation, there is RequestBuilderTransform parameter, not sure if this can help. But again cannot find any example or documentation on this. I want to cache loaded images in the disk.

Or, is there a global option we can set while using Jetpack Compose?

Using implementation "com.github.bumptech.glide:compose:1.0.0-beta01".

1

There are 1 best solutions below

0
ucMedia On

As far as I know you have two options:

1. Enable disk caching globally, This approach will apply disk caching to all image loading operations within your application:

   GlideApp
   .with(applicationContext)
   .applyDefaultRequestOptions(
    RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL) )

2. Or for each request, this will load the image from the provided URL and cache both the original and resized versions on the storage

    GlideImage(imageModel = { imageUrl },
       requestOptions = { RequestOptions()
          .diskCacheStrategy(DiskCacheStrategy.ALL)
       })