Get all data (from cache) for class when activity is created?

46 views
Skip to first unread message

Damian Mazurkiewicz

unread,
Nov 25, 2014, 4:51:31 AM11/25/14
to robo...@googlegroups.com
Hello,

What would be the best way to get all available cache data for class when activity is created if I don't know how much data is actually there and I don't know each cache key? getAllCacheKeys is synchronous method which does not really allow me to update all data without freezing UI.

Thoughts?

Damian

Nikola Keskinov

unread,
Nov 26, 2014, 4:31:13 AM11/26/14
to robo...@googlegroups.com
Hi Damian,

Would com.octo.android.robospice.SpiceManager#getAllDataFromCache help?

Nikola

Damian Mazurkiewicz

unread,
Dec 2, 2014, 12:25:26 PM12/2/14
to robo...@googlegroups.com
Hi Nikola,

I have tried getAllDataFromCache but it blocks UI until Future is returned. I was thinking about using another request to get my objects from cache for given Class.

What I want to achieve is onActivityCreation, grab all cache keys from database and data (fill the listview) and then execute requests based on the cache keys that are found in the cache.

Thanks,
Damian

Nikola Keskinov

unread,
Dec 2, 2014, 3:56:00 PM12/2/14
to robo...@googlegroups.com
Hi Damian,

Maybe I don't have the whole picture, but it seems that you can use com.octo.android.robospice.SpiceManager#getFromCache with DurationInMillis.ALWAYS_RETURNED, if you have all the needed cache keys. That method is asynchronous and needs a simple com.octo.android.robospice.request.listener.RequestListener to call back.

Regards,
Nikola

--
Vous recevez ce message, car vous êtes abonné à un sujet dans le groupe Google Groupes "RoboSpice".
Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/robospice/SeYxhok3dqo/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Damian Mazurkiewicz

unread,
Dec 2, 2014, 6:26:50 PM12/2/14
to robo...@googlegroups.com
Hi Nikola, I understand that part but I don't know my cache keys at runtime.

Thanks

Nikola Keskinov

unread,
Dec 3, 2014, 7:04:51 AM12/3/14
to robo...@googlegroups.com
Hi Damian,

It would require some more work to make it complete and robust, but you may have to think about calling Future.get() in an AsyncTask.
There is no async way of obtaining all cache keys in RoboSpice currently, but it would also be a challenge to implement one because cache stores various types and RequestListener is bound to a single one.

I would, however, suggest that you revise your app architecture, as it is pretty unusual to have such a requirement. I believe it is possible to either have a single type for all various objects you store in cache (in which case you will be able to use com.octo.android.robospice.SpiceManager#getFromCache easily), or have better control of the cache keys at runtime, so you will specifically know which ones you need.

Sorry for not having anything more useful, but if you give us some more details on the way you use RoboSpice (e.g. how is the cache filled in the first place), maybe we will be able to help more.

Regards,
Nikola

On Wed Dec 03 2014 at 12:26:50 AM Damian Mazurkiewicz <mazurkiew...@mazurlabs.com> wrote:
Hi Nikola,  I understand that part but I don't know my cache keys at runtime.

Thanks

--
Vous recevez ce message car vous êtes abonné à un sujet dans le groupe Google Groupes "RoboSpice".

Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/robospice/SeYxhok3dqo/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse robospice+unsubscribe@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/d/optout .

Damian Mazurkiewicz

unread,
Dec 3, 2014, 7:45:23 AM12/3/14
to robo...@googlegroups.com
Hi Nikola,

The user is provided with search function that allows to search for items (which have unique id which is also used as cache key). Each user might have different items on different devices. What I want to do is show all those items on the startup of the app which means that I need to find out cache keys for Class (just one class). and then execute requests for all this data.

Do you have any more ideas? I am trying to ignore AsyncTask as long as possible :)

Cheers,
Damian
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.

Nikola Keskinov

unread,
Dec 3, 2014, 9:12:22 AM12/3/14
to robo...@googlegroups.com
Since you have their unique identifiers upfront (in order to specify them to RoboSpice during requests), you may probably maintain a collection of those IDs in cache as an object of some new class. You will have a constant cache key for that collection and get it from cache initially. Then you will be able to query for each of the collection elements.

Regards,
Nikola

On Wed Dec 03 2014 at 1:45:24 PM Damian Mazurkiewicz <mazurkiew...@mazurlabs.com> wrote:
Hi Nikola,

The user is provided with search function that allows to search for items (which have unique id which is also used as cache key). Each user might have different items on different devices. What I want to do is show all those items on the startup of the app which means that I need to find out cache keys for Class (just one class). and then execute requests for all this data.

Do you have any more ideas? I am trying to ignore AsyncTask as long as possible :)

Cheers,
Damian


On Wednesday, 3 December 2014 12:04:51 UTC, Nikola Keskinov wrote:
Hi Damian,

It would require some more work to make it complete and robust, but you may have to think about calling Future.get() in an AsyncTask.
There is no async way of obtaining all cache keys in RoboSpice currently, but it would also be a challenge to implement one because cache stores various types and RequestListener is bound to a single one.

I would, however, suggest that you revise your app architecture, as it is pretty unusual to have such a requirement. I believe it is possible to either have a single type for all various objects you store in cache (in which case you will be able to use com.octo.android.robospice.SpiceManager#getFromCache easily), or have better control of the cache keys at runtime, so you will specifically know which ones you need.

Sorry for not having anything more useful, but if you give us some more details on the way you use RoboSpice (e.g. how is the cache filled in the first place), maybe we will be able to help more.

Regards,
Nikola

On Wed Dec 03 2014 at 12:26:50 AM Damian Mazurkiewicz <mazurkiew...@mazurlabs.com> wrote:
Hi Nikola,  I understand that part but I don't know my cache keys at runtime.

Thanks

--
Vous recevez ce message car vous êtes abonné à un sujet dans le groupe Google Groupes "RoboSpice".
Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/robospice/SeYxhok3dqo/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.

Pour plus d'options, visitez le site https://groups.google.com/d/optout .

--
Vous recevez ce message, car vous êtes abonné à un sujet dans le groupe Google Groupes "RoboSpice".

Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/robospice/SeYxhok3dqo/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.

Damian Mazurkiewicz

unread,
Dec 3, 2014, 10:11:22 AM12/3/14
to robo...@googlegroups.com
Thanks Nikola,

This is a great response which I haven't thought of!
Reply all
Reply to author
Forward
0 new messages