Acache class Download Address: Http://pan.baidu.com/s/1gfI0A9X
1. Create Acache instance
Acache Acache;
Acache = Acache.get (This, "main");
2, Save the data (memory and file)
Acache.put (Key,value,time);
The top two need not repeat, key-value pairs, last time, incoming int type, in seconds, representing the time that the cache exists, beyond which the cached data is purged.
3, get the cached data
Use an example to describe the problem:
| The code is as follows |
Copy Code |
|
public class Mainactivity extends activity {
Private ImageView img;
Acache Acache;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Acache = Acache.get (This, "main");
img = (imageview) Findviewbyid (r.id.img);
if (Acache.getasbitmap ("pic")!= null) {
LOG.E ("Acache", "caching is in use!");
Img.setimagebitmap (Acache.getasbitmap ("pic"));
} else {
Picasso.with (this). Load (' http://www.b.hsgjxt.com/image/cache/data/0-100x100.jpg '). into (new Target () {
@Override
public void onbitmaploaded (Bitmap Bitmap, picasso.loadedfrom from) {
LOG.E ("Picasso", "Using picasso!");
Img.setimagebitmap (bitmap);
Acache.put ("Pic", bitmap, 10);
}
@Override
public void onbitmapfailed (drawable errordrawable) {
}
@Override
public void Onprepareload (drawable placeholderdrawable) {
}
});
}
}
} |
When I first entered, the console printed the following:
When I immediately quit and went in, print as follows:
When I was delayed for about 10 seconds to go in again, and prompted as follows:
To prove that the cache is available, and that the cached time is also effective.