title: Glide : How to find if the image is already cached and use the cached version?
body: <p><strong>Scenario</strong>: </p>
  
  <p>I have a large GIF image which I want to cache the first time user opens the app using <a href="https://github.com/bumptech/glide" rel="noreferrer">Glide</a> - Image Loading and Caching library. After that whenever user opens the app, I want to show the cached version if present. This GIF URL will expire after a given interval. When it expires, I fetch the new GIF URL and display/cache that for future use.</p>
  
  <p><strong>What I tried:</strong></p>
  
  <p>I went through <a href="https://github.com/bumptech/glide/wiki/Caching-and-Cache-Invalidation" rel="noreferrer">Caching and Cache Invalidation</a> on Glide's github page. I also went though the Google Group thread <a href="https://groups.google.com/forum/#!topic/glidelibrary/TcFOy0tcxXA" rel="noreferrer">Ensuring That Images Loaded Only Come From Disk Cache</a>, which shows how to get the image form cache. I also went through <a href="https://stackoverflow.com/questions/31537669/how-to-invalidate-glide-cache-for-some-specific-images">How to invalidate Glide cache for some specific images</a> question.</p>
  
  <p>From the links above I see the following code sniplet which shows how to load the image from cache. However this only tries to get the image from cache. If its not present in cache, it doesn't try to get from the network and fails:</p>
  
  <pre><code>Glide.with(TheActivity.this)
          .using(new StreamModelLoader&lt;String&gt;() {
              @Override
              public DataFetcher&lt;InputStream&gt; getResourceFetcher(final String model, int i, int i1) {
                  return new DataFetcher&lt;InputStream&gt;() {
                      @Override
                      public InputStream loadData(Priority priority) throws Exception {
                          throw new IOException();
                      }
  
                      @Override
                      public void cleanup() {
                      }
  
                      @Override
                      public String getId() {
                          return model;
                      }
  
                      @Override
                      public void cancel() {
                      }
                  };
              }
          })
         .load("http://sampleurl.com/sample.gif")
         .diskCacheStrategy(DiskCacheStrategy.SOURCE)
         .into(theImageView);
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li><p>Is there a cleaner way to achieve the following: Show the GIF image from the cache if present else download the GIF, cache it for later use and show it in the <code>ImageView</code>.</p></li>
  <li><p>The caching article above mentions the following: </p>
  
  <blockquote>
    <p>In practice, the best way to invalidate a cache file is to change
    your identifier when the content changes (url, uri, file path etc)</p>
  </blockquote>
  
  <p>The server sends a different URL to the app when the previous one expires. In this case, I believe the old image will eventually be Garbage Collected? Is there a way to force remove the image from the cache?</p></li>
  <li><p>On a similar note, is there a way to prevent the Garbage Collection of an image with specific key (to prevent downloading the large file again) and then later instruct to delete the old image from cache when the URL changes?</p></li>
  </ol>