Question

I have an android app using Robospice with Jackson + Spring to perform REST requests. This is working, except that Robospice doesn't seem to be caching the responses. I've also made sure that the cache key is consistent between requests.

I'm setting up the SpiceManager like this:

 private SpiceManager mRestManager = new SpiceManager(JacksonSpringAndroidSpiceService.class);

Then, I'm executing the request like this:

mRestManager.execute(customSpiceRequest, requestCacheKey, 
            DurationInMillis.ALWAYS, new CustomRequestListener())

I don't know if it's relevant, but my customSpiceRequest extends SpringAndroidSpiceRequest. I've made certain that requestCacheKey is identical between requests too.

Is there something else I need to do to enable caching between requests?

Était-ce utile?

La solution

Indeed, RoboSpice is doing what you are asking for : you pass DurationInMillis.ALWAYS as a parameter to execute.

This means that the data in cache will always be considered expired. Thus, the SpiceRequest will always perform a network call. You should just use a different cacheDuration value when invoking execute.

Since then, Javadoc has been enhanced :

  • cacheExpiryDuration : duration in millisecond after which the content of the cache will be considered to be expired. For instance DurationInMillis.ALWAYS means that data in cache will always be considered expired, thus requests will always perform their network operations to get new data. DurationInMillis.NEVER means data will never be considered as expired, requests will never perform network operations to refresh data but will always return cached data. (see {@link DurationInMillis}).*
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top