title: ExoPlayer, generalize SimpleCache behaviour
body: <p>I'm using ExoPlayer 2 to play music from the web. Now I want to cache downloaded music by using the beautiful <code>SimpleCache</code> class. My problem is the following: every time I request to play a song, the server returns me a different URL (also for the same song), which is used as key by <code>SimpleCache</code>. Consequently, <code>SimpleCache</code> creates a new cache file for each URL (i.e. also a different file for the same song).</p>
  
  <p>It would be nice if there was a way to ask me what is the key of the cached file generated for a particular url. Do you know a way to do that?</p>
  
  <p>The <code>SimpleCache</code> class is <code>final</code>, so I cannot override its methods.</p>
  
  <p><br/></p>
  
  <p><strong>EDIT, a rough solution:</strong><br/>
  I created a copy of <code>CacheDataSource</code> and changed just this line in the method <code>open(DataSpec)</code>, which is responsible of keys' generation:</p>
  
  <pre><code>key = dataSpec.key != null ? dataSpec.key : uri.toString();
  </code></pre>
  
  <p>I could generate the same key thanks to some <code>uri</code>'s parameters which are equals for each url retrieved for the same song. This solution solves my problem but is not so generic and exploitable for every possible case.</p>
  
  <p>The <code>CacheDataSource</code> has been then used as explained in <a href="https://github.com/google/ExoPlayer/issues/420#issuecomment-244652023" rel="noreferrer">this comment</a>:</p>
  
  <pre><code>private DataSource.Factory buildDataSourceFactory(final boolean useBandwidthMeter) {
      return new DataSource.Factory() {
          @Override
          public DataSource createDataSource() {
              LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(100 * 1024 * 1024);
              SimpleCache simpleCache = new SimpleCache(new File(getCacheDir(), "media_cache"), evictor);
              return new CacheDataSource(
                  simpleCache,
                  buildMyDataSourceFactory(useBandwidthMeter).createDataSource(),
                  CacheDataSource.FLAG_BLOCK_ON_CACHE,
                  10 * 1024 * 1024
              );
          }
      };
  }
  
  private DefaultDataSource.Factory buildMyDataSourceFactory(boolean useBandwidthMeter) {
      return new DefaultDataSourceFactory(PlayerActivity.this, userAgent, useBandwidthMeter ? BANDWIDTH_METER : null);
  }
  </code></pre>