simple-disk-cache icon indicating copy to clipboard operation
simple-disk-cache copied to clipboard

Could not use SimpleDiskCache.

Open MustafaBaquari opened this issue 11 years ago • 2 comments

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);

MustafaBaquari avatar Jun 24 '13 11:06 MustafaBaquari

Not sure if it would solve the problem, but I think you should call is.close(); immediately after cache.put("test", is);

fhucho avatar Jul 26 '13 18:07 fhucho

How to store Bitmap with String key ? @fhucho

jemshit avatar Jul 12 '16 12:07 jemshit