simple-disk-cache
simple-disk-cache copied to clipboard
Could not use SimpleDiskCache.
I used this code to cache and retrive an Image file. The bitmap returned in last line was null. I used debug and observed each step and in every step there was something in all the variables. (I mean to say they were not null except for bitmap in last line.) I know there is a method to get bitmaps directly but I wanted a method to write any type of file in cache and retrieve them.
SimpleDiskCache cache = SimpleDiskCache.open(getCacheDir(), 1, (long) 1024 * 1024 *10 ); // 10 MB
ImageHandler ih = new ImageHandler(context);
URL url = new URL("ImageUrl");
URLConnection conection = url.openConnection();
conection.connect();
InputStream is = url.openStream();
cache.put("test", is);
InputStreamEntry returnIS = cache.getInputStream("test");
InputStream is2 = returnIS.getInputStream();
returnIS.close();
is.close();
System.out.println(is2.toString().trim());
Bitmap bmp = BitmapFactory.decodeStream(is2);
Not sure if it would solve the problem, but I think you should call is.close();
immediately after cache.put("test", is);
How to store Bitmap with String key ? @fhucho