com.nostra13.universalimageloader.cache.disc.impl.ext
Class LruDiscCache

java.lang.Object
  extended by com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiscCache
All Implemented Interfaces:
DiscCacheAware, DiskCache

public class LruDiscCache
extends Object
implements DiskCache

Disk cache based on "Least-Recently Used" principle. Adapter pattern, adapts DiskLruCache to DiskCache

Since:
1.9.2
Author:
Sergey Tarasevich (nostra13[at]gmail[dot]com)
See Also:
FileNameGenerator

Field Summary
protected  int bufferSize
           
protected  com.nostra13.universalimageloader.cache.disc.impl.ext.DiskLruCache cache
           
protected  android.graphics.Bitmap.CompressFormat compressFormat
           
protected  int compressQuality
           
static int DEFAULT_BUFFER_SIZE
          {@value
static android.graphics.Bitmap.CompressFormat DEFAULT_COMPRESS_FORMAT
          {@value
static int DEFAULT_COMPRESS_QUALITY
          {@value
protected  FileNameGenerator fileNameGenerator
           
 
Constructor Summary
LruDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize, int cacheMaxFileCount)
           
LruDiscCache(File cacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize)
           
 
Method Summary
 void clear()
          Clears disk cache.
 void close()
          Closes disk cache, releases resources.
 File get(String imageUri)
          Returns file of cached image
 File getDirectory()
          Returns root directory of disk cache
 boolean remove(String imageUri)
          Removes image file associated with incoming URI
 boolean save(String imageUri, android.graphics.Bitmap bitmap)
          Saves image bitmap in disk cache.
 boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener)
          Saves image stream in disk cache.
 void setBufferSize(int bufferSize)
           
 void setCompressFormat(android.graphics.Bitmap.CompressFormat compressFormat)
           
 void setCompressQuality(int compressQuality)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
{@value

See Also:
Constant Field Values

DEFAULT_COMPRESS_FORMAT

public static final android.graphics.Bitmap.CompressFormat DEFAULT_COMPRESS_FORMAT
{@value


DEFAULT_COMPRESS_QUALITY

public static final int DEFAULT_COMPRESS_QUALITY
{@value

See Also:
Constant Field Values

cache

protected com.nostra13.universalimageloader.cache.disc.impl.ext.DiskLruCache cache

fileNameGenerator

protected final FileNameGenerator fileNameGenerator

bufferSize

protected int bufferSize

compressFormat

protected android.graphics.Bitmap.CompressFormat compressFormat

compressQuality

protected int compressQuality
Constructor Detail

LruDiscCache

public LruDiscCache(File cacheDir,
                    FileNameGenerator fileNameGenerator,
                    long cacheMaxSize)
             throws IOException
Parameters:
cacheDir - Directory for file caching
fileNameGenerator - Name generator for cached files. Generated names must match the regex [a-z0-9_-]{1,64}
cacheMaxSize - Max cache size in bytes. 0 means cache size is unlimited.
Throws:
IOException - if cache can't be initialized (e.g. "No space left on device")

LruDiscCache

public LruDiscCache(File cacheDir,
                    File reserveCacheDir,
                    FileNameGenerator fileNameGenerator,
                    long cacheMaxSize,
                    int cacheMaxFileCount)
             throws IOException
Parameters:
cacheDir - Directory for file caching
reserveCacheDir - null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
fileNameGenerator - Name generator for cached files. Generated names must match the regex [a-z0-9_-]{1,64}
cacheMaxSize - Max cache size in bytes. 0 means cache size is unlimited.
cacheMaxFileCount - Max file count in cache. 0 means file count is unlimited.
Throws:
IOException - if cache can't be initialized (e.g. "No space left on device")
Method Detail

getDirectory

public File getDirectory()
Description copied from interface: DiscCacheAware
Returns root directory of disk cache

Specified by:
getDirectory in interface DiscCacheAware
Returns:
Root directory of disk cache

get

public File get(String imageUri)
Description copied from interface: DiscCacheAware
Returns file of cached image

Specified by:
get in interface DiscCacheAware
Parameters:
imageUri - Original image URI
Returns:
File of cached image or null if image wasn't cached

save

public boolean save(String imageUri,
                    InputStream imageStream,
                    IoUtils.CopyListener listener)
             throws IOException
Description copied from interface: DiscCacheAware
Saves image stream in disk cache.

Specified by:
save in interface DiscCacheAware
Parameters:
imageUri - Original image URI
imageStream - Input stream of image
listener - Listener for saving progress, can be ignored if you don't use progress listener in ImageLoader calls
Returns:
true - if image was saved successfully; false - if image wasn't saved in disk cache.
Throws:
IOException

save

public boolean save(String imageUri,
                    android.graphics.Bitmap bitmap)
             throws IOException
Description copied from interface: DiscCacheAware
Saves image bitmap in disk cache.

Specified by:
save in interface DiscCacheAware
Parameters:
imageUri - Original image URI
bitmap - Image bitmap
Returns:
true - if bitmap was saved successfully; false - if bitmap wasn't saved in disk cache.
Throws:
IOException

remove

public boolean remove(String imageUri)
Description copied from interface: DiscCacheAware
Removes image file associated with incoming URI

Specified by:
remove in interface DiscCacheAware
Parameters:
imageUri - Image URI
Returns:
true - if image file is deleted successfully; false - if image file doesn't exist for incoming URI or image file can't be deleted.

close

public void close()
Description copied from interface: DiscCacheAware
Closes disk cache, releases resources.

Specified by:
close in interface DiscCacheAware

clear

public void clear()
Description copied from interface: DiscCacheAware
Clears disk cache.

Specified by:
clear in interface DiscCacheAware

setBufferSize

public void setBufferSize(int bufferSize)

setCompressFormat

public void setCompressFormat(android.graphics.Bitmap.CompressFormat compressFormat)

setCompressQuality

public void setCompressQuality(int compressQuality)


Copyright © 2011-2014. All Rights Reserved.