title: Android:Cache Validity for an Image using coil in jetpack
body: <p>I am facing issue in setting validity for Cache in android jetpack using coil.
  <strong>What I Need</strong>: In Android Jetpack compose, I need to download an SVG image from the Url and store it to the cache. But the cache should store the image only for 20 seconds. so within the 20 seconds, there should not be any further image request. For this 20 seconds, the image should display from the cache. After 20 seconds, I want the image, should get cleared from the cache.</p>
  <p><strong>What's the problem I am facing:</strong> The image is not getting cleared from the cache even after 20 seconds. I am using Coil for the jetpack compose<a href="https://coil-kt.github.io/coil/compose/" rel="noreferrer"> jetpack coil</a> and <a href="https://coil-kt.github.io/coil/recipes/#headers" rel="noreferrer"> Jetpack header for Cachecontrol </a>
  Thanks in Advance....</p>
  <p>In Application Class, I created a single instance ImageLoader</p>
  <pre><code>val imageLoader = ImageLoader.Builder(applicationContext)
              .componentRegistry {
                  add(SvgDecoder(applicationContext))
              }
              .okHttpClient {
                  OkHttpClient.Builder()
                          .cache(CoilUtils.createDefaultCache(applicationContext))
                          .addNetworkInterceptor(provideCacheInterceptor(10))
                          .build()
  
              }
              .memoryCachePolicy(CachePolicy.DISABLED)
              .diskCachePolicy(CachePolicy.ENABLED)
              .build()
  
      Coil.setImageLoader(imageLoader = imageLoader)
  </code></pre>
  <p>In Moment.class:</p>
  <pre><code>val singleInstanceImageLoader = context.imageLoader
  val imageRequest = ImageRequest.Builder(context)
                  .data(decodedURL)
                  .memoryCachePolicy(CachePolicy.DISABLED)
                  .diskCachePolicy(CachePolicy.ENABLED)
                 .addHeader(&quot;Cache-Control&quot;, &quot;max-age=20,public&quot;)
                 .build()
  
          val imagePainter = rememberCoilPainter(
                  request = imageRequest,
                  imageLoader = singleInstanceImageLoader
          )
  
          Image(
                  painter = imagePainter,
                  contentDescription = null,
                  modifier = Modifier
                          .wrapContentSize(Alignment.Center)
                          .padding(0.dp, 15.dp, 0.dp, 15.dp)
  
          )
  </code></pre>