Clear selected cache file

46 views
Skip to first unread message

CS

unread,
Jan 1, 2014, 3:53:10 AM1/1/14
to codenameone...@googlegroups.com
Dear Shai,

I noticed that in Storage class there is a method

public void clearCache() {
        cache.clearAllCache();
}

but I am missing a method to clear/delete the cache of only a specific file (and not deleting the actual file), which I would find really useful. Something like

public void clearCache(String name) {
        cache.delete(name);
}

Could such method be added in near future? Or is there any other way to do this, without writing own "storage" class?

Happy new Year to you all.

Shai Almog

unread,
Jan 1, 2014, 12:42:32 PM1/1/14
to codenameone...@googlegroups.com, computer.s...@gmail.com
Hi,
why would you want to do that?
clearing the cache isn't destructive so it shouldn't be a big deal if you clear all the cache occasionally.

CS

unread,
Jan 2, 2014, 12:30:00 PM1/2/14
to codenameone...@googlegroups.com
I read somewhere (probably in one of your blogs, but I could be wrong), that the main problem of reading (directly from storage) is poor performance (compared to from RAM).

So my concern is purely performance wise. Let me give you an example.
If I have one "big" file (which is always used only for reading) and one small file. In such cases when I want to clear cache of small file, also the "big" file is cleared from cache. On next access to the big file, it needs to be read from storage and consequently as such this operation is slow. If I would be able to clear only cache of small file, this would not be a problem.

This is my reasoning behind my "wish", but I could be wrong ...

Shai Almog

unread,
Jan 2, 2014, 2:48:53 PM1/2/14
to codenameone...@googlegroups.com, computer.s...@gmail.com
If you have a large file that you keep in cache you are better off removing it from cache since memory is far more precious than CPU on mobile devices. This obviously depends on how you read this and why you need to clear the cache in the first place?
Do you understand the reason for that method?
You don't need to clear the cache for most common use cases.

CS

unread,
Jan 3, 2014, 10:32:26 AM1/3/14
to codenameone...@googlegroups.com
Well I hope my read only file will not be too large (the size should be from 1MB to 10 MB; such is my current estimation). Since one of the main operations is searching for the data in this file and consequently I would have to read a lot of data from storage, it would be really a performance problem, if it would not be in cache.

The reason for clearing cache is in my current implementation, since this is the easiest way. All the changes are done in cache and are only stored to storage on "save". So, if a user decides to "cancel" current "unsaved" (to storage) work, clearing the cache sounds simple and efficient.

I agree that one could/should implement this in different way … But adding one public function for clearing specific cached file does not sound so awful, too. ;-)

In the end, it is you choice to decide, this is just my suggestion/input on this matter.

Shai Almog

unread,
Jan 3, 2014, 3:01:22 PM1/3/14
to codenameone...@googlegroups.com, computer.s...@gmail.com
Your use case makes sense. My main concern is that developers won't understand this use case and use it as a delete function.
Its a bit problematic to clear an individual entry.

CS

unread,
Jan 5, 2014, 10:02:37 AM1/5/14
to codenameone...@googlegroups.com
I am really glad you see a possible usage of my request.

So, for now I will keep using clearAllCache() and hope that you find this worthwhile to implement. I for one will certainly not mind.
Reply all
Reply to author
Forward
0 new messages