1package com.bumptech.glide.load.engine; 2 3import android.util.Log; 4 5import com.bumptech.glide.load.Key; 6import com.bumptech.glide.load.ResourceDecoder; 7import com.bumptech.glide.load.engine.cache.DiskCache; 8 9import java.io.File; 10import java.io.IOException; 11 12class CacheLoader { 13 private static final String TAG = "CacheLoader"; 14 private final DiskCache diskCache; 15 16 public CacheLoader(DiskCache diskCache) { 17 this.diskCache = diskCache; 18 } 19 20 public <Z> Resource<Z> load(Key key, ResourceDecoder<File, Z> decoder, int width, int height) { 21 File fromCache = diskCache.get(key); 22 if (fromCache == null) { 23 return null; 24 } 25 26 Resource<Z> result = null; 27 try { 28 result = decoder.decode(fromCache, width, height); 29 } catch (IOException e) { 30 if (Log.isLoggable(TAG, Log.DEBUG)) { 31 Log.d(TAG, "Exception decoding image from cache", e); 32 } 33 } 34 if (result == null) { 35 if (Log.isLoggable(TAG, Log.DEBUG)) { 36 Log.d(TAG, "Failed to decode image from cache or not present in cache"); 37 } 38 diskCache.delete(key); 39 } 40 return result; 41 } 42} 43