com.nostra13.universalimageloader.cache.memory.impl
Class LruMemoryCache

java.lang.Object
  extended by com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache
All Implemented Interfaces:
MemoryCache, MemoryCacheAware<String,android.graphics.Bitmap>

public class LruMemoryCache
extends Object
implements MemoryCache

A cache that holds strong references to a limited number of Bitmaps. Each time a Bitmap is accessed, it is moved to the head of a queue. When a Bitmap is added to a full cache, the Bitmap at the end of that queue is evicted and may become eligible for garbage collection.

NOTE: This cache uses only strong references for stored Bitmaps.

Since:
1.8.1
Author:
Sergey Tarasevich (nostra13[at]gmail[dot]com)

Constructor Summary
LruMemoryCache(int maxSize)
           
 
Method Summary
 void clear()
          Remove all items from cache
 android.graphics.Bitmap get(String key)
          Returns the Bitmap for key if it exists in the cache.
 Collection<String> keys()
          Returns all keys of cache
 boolean put(String key, android.graphics.Bitmap value)
          Caches Bitmap for key.
 android.graphics.Bitmap remove(String key)
          Removes the entry for key if it exists.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LruMemoryCache

public LruMemoryCache(int maxSize)
Parameters:
maxSize - Maximum sum of the sizes of the Bitmaps in this cache
Method Detail

get

public final android.graphics.Bitmap get(String key)
Returns the Bitmap for key if it exists in the cache. If a Bitmap was returned, it is moved to the head of the queue. This returns null if a Bitmap is not cached.

Specified by:
get in interface MemoryCacheAware<String,android.graphics.Bitmap>

put

public final boolean put(String key,
                         android.graphics.Bitmap value)
Caches Bitmap for key. The Bitmap is moved to the head of the queue.

Specified by:
put in interface MemoryCacheAware<String,android.graphics.Bitmap>
Returns:
true - if value was put into cache successfully, false - if value was not put into cache

remove

public final android.graphics.Bitmap remove(String key)
Removes the entry for key if it exists.

Specified by:
remove in interface MemoryCacheAware<String,android.graphics.Bitmap>

keys

public Collection<String> keys()
Description copied from interface: MemoryCacheAware
Returns all keys of cache

Specified by:
keys in interface MemoryCacheAware<String,android.graphics.Bitmap>

clear

public void clear()
Description copied from interface: MemoryCacheAware
Remove all items from cache

Specified by:
clear in interface MemoryCacheAware<String,android.graphics.Bitmap>

toString

public final String toString()
Overrides:
toString in class Object


Copyright © 2011-2014. All Rights Reserved.