Skip to content

Instantly share code, notes, and snippets.

@brk3
Created November 30, 2013 19:52
Show Gist options
  • Save brk3/7723643 to your computer and use it in GitHub Desktop.
Save brk3/7723643 to your computer and use it in GitHub Desktop.
Singleton to manage and access Picasso cache
package com.bourke.glimmr.common;
import android.content.Context;
import com.squareup.picasso.LruCache;
import com.squareup.picasso.Picasso;
public class PicassoHelper {
private static final String TAG = "Glimmr/PicassoHelper";
private static PicassoHelper singleton;
private Picasso mPicasso;
private LruCache mCache;
private PicassoHelper() {
}
public static PicassoHelper getInstance(Context context) {
if (singleton == null) {
singleton = new PicassoHelper();
LruCache cache = new LruCache(context);
singleton.mCache = cache;
singleton.mPicasso = new Picasso.Builder(context)
.memoryCache(cache).debugging(true)
.build();
}
return singleton;
}
public Picasso getPicasso() {
return mPicasso;
}
public LruCache getCache() {
return mCache;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment