public static int parseColor(String colorString, int defaultColor) { try { Integer integer = colorCache.get(colorString); if (integer != null) { return integer.intValue(); } else { integer = Color.parseColor(colorString); colorCache.put(colorString, integer); return integer.intValue(); } } catch (Exception e) { return defaultColor; } }
private void clearCache() { mCache.evictAll(); }
@NonNull public static LruCache<Long, GalleryDetail> getGalleryDetailCache(@NonNull Context context) { EhApplication application = ((EhApplication) context.getApplicationContext()); if (application.mGalleryDetailCache == null) { // Max size 25, 3 min timeout application.mGalleryDetailCache = new LruCache<>(25); } return application.mGalleryDetailCache; }
@Override void put(int key, Object object) { mCache.put(key, object); } }
private Bitmap getVideoThumbToCache(String path) { return lruCache.get(path); }
@Test public void testCachingSpannableString() { SpannableStringBuilder spannable = new SpannableStringBuilder("This is a bold text"); spannable.setSpan(new StyleSpan(Typeface.BOLD), 10, 13, Spanned.SPAN_INCLUSIVE_INCLUSIVE); mLayout = mBuilder.setText(spannable).setShouldCacheLayout(true).build(); assertEquals(mBuilder.sCache.size(), 1); assertEquals(mBuilder.sCache.get(mBuilder.mParams.hashCode()), mLayout); }
public void removeInfo(int serviceId, @NonNull String url) { if (DEBUG) Log.d(TAG, "removeInfo() called with: serviceId = [" + serviceId + "], url = [" + url + "]"); synchronized (lruCache) { lruCache.remove(keyOf(serviceId, url)); } }
public void putImagesCache(String groundOverlayUrl, Bitmap bitmap) { mImagesCache.put(groundOverlayUrl, bitmap); }
@Override @Nullable <T> T get(int key) { return (T) mCache.get(key); }
/** * 移除缓存 * @param url */ public void removeBitmapCache(String url) { if (url != null && mCache != null) { Bitmap bm = mCache.remove(url); if (bm != null) { bm.recycle(); } } }
public static int parseColor(String colorString, int defaultColor) { try { Integer integer = colorCache.get(colorString); if (integer != null) { return integer.intValue(); } else { integer = Color.parseColor(colorString); colorCache.put(colorString, integer); return integer.intValue(); } } catch (Exception e) { return defaultColor; } }
private void addVideoThumbToCache(String path, Bitmap bitmap) { if (getVideoThumbToCache(path) == null && bitmap != null) { // 当前地址没有缓存时,就添加 lruCache.put(path, bitmap); } }
@Nullable public <T> T get(@NonNull final String key, @NonNull final Class<T> type) { if (DEBUG) Log.d(TAG, "get() called with: key = [" + key + "]"); synchronized (lruCache) { final CacheData data = lruCache.get(key); return data != null ? getItem(data, type) : null; } }