yangfuhai / ASimpleCache

a simple cache for android and java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion for the project.

alexsilva opened this issue · comments

commented

I like how the project was created but did not understand why this:

        public void put(String key, byte[] value) {
                File file = mCache.newFile(key);
                FileOutputStream out = null;
                try {
                        out = new FileOutputStream(file);
                        out.write(value);
                } catch (Exception e) {
                        e.printStackTrace();
                } finally {
                        if (out != null) {
                                try {
                                        out.flush();
                                        out.close();
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                        }
                        mCache.put(file);
                }
        }

When the api cache provides the ability to save in the cache based on File:

private void put(File file)

Faced with this situation, I suggest (what I currently need) that create a method that works with File(public):

public void put(File file)

So I could add a File in Cache, more record (when necessary), using a FileInputStream. Would look like this:

 File mFile = new File("test.txt");

 ACache mCache = ACache.get(this);
 mCache.put("myFileKey", mFile);

 FileOutputStream out = new FileOutputStream(mFile);
 out.write("my bytes".getBytes());

The need then arose to write because I need to save content from the internet (save a cache of bytes in memory is not an option).

commented

Cool, it is now possible work with streams.