An open API service indexing awesome lists of open source software.

https://github.com/sephiroth74/disklruimagecache

Simple file based image cache
https://github.com/sephiroth74/disklruimagecache

Last synced: 9 months ago
JSON representation

Simple file based image cache

Awesome Lists containing this project

README

          

DiskLruImageCache
=================

Simple file based image cache

Include
=================

Just add the following line to your build.gradle dependencies

compile "it.sephiroth.android.library.disklruimagecache:DiskLruImageCache:1.0.0"

Usage
=================

DiskLruImageCache cache = new DiskLruImageCache( context, "my-unique-name", Integer.MAX_VALUE );

Read an entry from the cache

DiskLruImageCache.BitmapEntry entry = cache.get( "image-1", Metadata.class );

Write an entry

Metadata metadata = new Metadata();
metadata.value = 1;
DiskLruImageCache.BitmapEntry entry;
entry = new DiskLruImageCache.BitmapEntry( bitmap, metadata );
boolean success = cache.put( "image-1", entry, Bitmap.CompressFormat.JPEG, 70 );

The Metadata must be an instance of Parcelable, in this example is:

static class Metadata implements Parcelable {

int value;

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Metadata createFromParcel ( Parcel source ) {
final Metadata f = new Metadata();
f.value = source.readInt();
return f;
}

@Override
public Metadata[] newArray ( final int i ) {
return new Metadata[0];
}
};

@Override
public int describeContents () {
return 0;
}

@Override
public void writeToParcel ( final Parcel parcel, final int i ) {
parcel.writeInt( value );
}
}