Open abreu-dev opened 10 years ago
@andreabreu-me I have read your thread a long time ago. I find it interesting but really I don't have enough time to read it in depth and try to see if I would like to implement it or not. But it really looks interesting...
I plan the feature for 1.5.0, hoping to get some time or some contribution for it.
Hi. i am digging into Robospice code to understand how it really works. I think executing a request is not simple. We have, setDirtyCache, setOffline, and a lot of execute methods in the spiceManager.
1) If i want to get some data from cache, i do:
This method will just execute a CachedSpiceRequest under the hood with a DummySpiceRequest (this DummySpiceRequest doesnt have a higher priority, why?), and will put setOffline flag to true. The cache policy here is CachePolicy.CACHE_ONLY.
2) If i want to get some data from cache if not expired or make a network request if cache expired, i do:
The cache policy here is CachePolicy.CACHE_FIRST.
3) If i want to get data from cache and load from network if cache expired, i do:
The cache policy here is CachePolicy.BOTH. Is this the best way to know if the data were retrieved from cache or network ?
Conclusion:
I think we just need two executes methods in spiceManager.
and we can execute requests like this:
CACHE POLICIES:
CachePolicy.NOCACHE: This policy will not use any caching, and will execute every request online. Use this policy if your application is dependant on data that is shared between multiple users and always needs to be up to date.
CachePolicy.CACHEONLY: This policy will only retrieve data from the cache, and will not use any network connection. Use this policy in combination with another policy, to allow for quick response times without requiring a network connection for specific operations.
CachePolicy.CACHEFIRST: This policy will first attempt to retrieve data from the cache. If the data has been cached, it will be returned. If the data does not exist in the cache, the data will be retrieved from "loadDataFromNetwork" and the cache will be updated. Use this policy if your application can display data that doesn't change very often but you still want local updates.
CachePolicy.CACHEFIRST_NOREFRESH: This policy will first attempt to retrieve data from the cache. If the data has been cached, it will be returned. If the data does not exist in the cache, the data will be retrieved from "loadDataFromNetwork" but the cache will not be updated with the new results. Use this policy if you want to set default results, however if a request is made that cannot return these defaults a live request will be made (without modifying those default values)
CachePolicy.NETWORKFIRST: This policy will execute the request on the network, and will store the result in the cache. If the network execution fails, the results will be pulled from the cache. Use this policy if your application wants the latest data but you still want responsiveness if a connection is lost
CachePolicy.BOTH: This policy will first retrieve an element from the cache, and then it will attempt to execute the request on line.
P.S.: English is not my native language
Thanks :)