1

I want to increase my Apps speed and avoid heavy calls to the server by applying Android LruCache. Here is my scenario :

I've create 2 LruCache objects.

private LruCache<String, List<Items>> mListItemsCache;

private LruCache<String, Items> mItemsCache;

mItemsCache will hold cache of all the items which could be retrieved by unique Id string. On the other hand mListItemsCache will be cached of all the different Items list. Each list was build base on available items on mItemsCache.

My question is that the Item which was retrieved from mListItemsCache or mItemsCache is actually the same Object ?

Does the data will be duplicated each time it was store to LruCache due to put(K,V)?

Van Vu
  • 11
  • 3

1 Answers1

0

I think more code would be necessary to give you an answer: What is Items? how can you measure Items in terms of bytes? Why do you need two caches for the same Item?

I would use a List (for mListItemsCache) where each String is a key to the cache Object (mItemsCache). So, whenever you add an Item to the cache (mItemsCache), add the key to the List (mListItemsCache) for example: mItemsCache.put(myKey, Items); mListItemsCache.add(myKey);

ja_mesa
  • 1,971
  • 1
  • 11
  • 7
  • oh well Items will just any particular Object which fetched from SQL row which such fields ID, Name etc ... let's think for instance that Items is information of Song and List would be a PlayList... so basically Both of them using the same Object Items nomatter a Cache of Items collection or a Cache of collection of Items collection would be best that just hold same object Items. List> could just change to List which CollectionItemsObject hold a reference to a List of Items ^.^ for more clear . – Van Vu Dec 03 '12 at 02:20