當前位置: 首頁>>代碼示例>>Java>>正文


Java LruCache.put方法代碼示例

本文整理匯總了Java中android.support.v4.util.LruCache.put方法的典型用法代碼示例。如果您正苦於以下問題:Java LruCache.put方法的具體用法?Java LruCache.put怎麽用?Java LruCache.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.util.LruCache的用法示例。


在下文中一共展示了LruCache.put方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insertIntoCache

import android.support.v4.util.LruCache; //導入方法依賴的package包/類
private void insertIntoCache() {
    synchronized (mCache) {
        LruCache<String, CollectionDAO> cache = mCache.get(collectionName);
        if (cache == null) {
            cache = new LruCache<>(50);
            mCache.put(collectionName, cache);
        }
        cache.put(documentID, this);
    }
}
 
開發者ID:lukamarin,項目名稱:Rocket.Chat-android,代碼行數:11,代碼來源:CollectionDAO.java

示例2: getImageLoader

import android.support.v4.util.LruCache; //導入方法依賴的package包/類
@NonNull
public static ImageLoader getImageLoader(@NonNull Context context) {
    MaxWidthImageLoader imageLoader = sMaxWidthImageLoader;
    // Double-check locking to initialize.
    if (imageLoader == null) {
        synchronized (Networking.class) {
            imageLoader = sMaxWidthImageLoader;
            if (imageLoader == null) {
                RequestQueue queue = getRequestQueue(context);
                int cacheSize = DeviceUtils.memoryCacheSizeBytes(context);
                final LruCache<String, Bitmap> imageCache = new LruCache<String, Bitmap>(cacheSize) {
                    @Override
                    protected int sizeOf(String key, Bitmap value) {
                        if (value != null) {
                            return value.getRowBytes() * value.getHeight();
                        }

                        return super.sizeOf(key, value);
                    }
                };
                imageLoader = new MaxWidthImageLoader(queue, context, new MaxWidthImageLoader.ImageCache() {
                    @Override
                    public Bitmap getBitmap(final String key) {
                        return imageCache.get(key);
                    }

                    @Override
                    public void putBitmap(final String key, final Bitmap bitmap) {
                        imageCache.put(key, bitmap);
                    }
                });
                sMaxWidthImageLoader = imageLoader;
            }
        }
    }
    return imageLoader;
}
 
開發者ID:JSafaiyeh,項目名稱:Fabric-Example-App-Android,代碼行數:38,代碼來源:Networking.java

示例3: testWeakDeletion

import android.support.v4.util.LruCache; //導入方法依賴的package包/類
@Test
public void testWeakDeletion() {
    final LruCache<String, String> cache = new WeakLruCache<>(1);

    // create Strings this way to prevent usage of intern table
    String val1 = new String(VALUE1);
    String val2 = new String(VALUE2);

    // populate the cache
    cache.put(KEY1, val1);
    assertEquals(1, cache.size());
    cache.put(KEY2, val2);
    assertEquals(1, cache.size());

    // controlled gc to make sure errors don't hide behind unscheduled GC's
    forceGc();

    // make sure both are still accessible
    assertEquals(VALUE1, cache.get(KEY1));
    assertEquals(VALUE2, cache.get(KEY2));

    // wipe local copy and force GC
    val1 = null;
    val2 = null;
    forceGc();

    // val1 should be missing now
    assertNull(cache.get(KEY1));
    assertNotEquals(VALUE1, cache.get(KEY1));
    assertEquals(VALUE2, cache.get(KEY2));
}
 
開發者ID:CruGlobal,項目名稱:android-gto-support,代碼行數:32,代碼來源:WeakLruCacheTest.java

示例4: doSaveOrUpdate

import android.support.v4.util.LruCache; //導入方法依賴的package包/類
private <T extends AbstractStorage> void doSaveOrUpdate(T t)
{
    Class tClass = t.getClass();
    LruCache<Serializable, T> cache = getFastLRUCache(tClass);
    cache.put(t.getId(), t);
}
 
開發者ID:ZhuoKeTeam,項目名稱:AndroidJsoup,代碼行數:7,代碼來源:StorageService.java

示例5: saveBitmapToMemory

import android.support.v4.util.LruCache; //導入方法依賴的package包/類
/**
 * put bitmap into LruCache
 *
 * @param bitmap
 */
protected void saveBitmapToMemory(Bitmap bitmap) {
    Log.d("LruImage", "saveBitmapToMemory");
    LruCache<String, Bitmap> lruCache = getLruCache();
    lruCache.put(getKey(), bitmap);
}
 
開發者ID:douo,項目名稱:lru-image,代碼行數:11,代碼來源:LruImage.java


注:本文中的android.support.v4.util.LruCache.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。