Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect if data is from cache #6

Open
tprochazka opened this issue Apr 12, 2012 · 5 comments
Open

Detect if data is from cache #6

tprochazka opened this issue Apr 12, 2012 · 5 comments

Comments

@tprochazka
Copy link

When I repeat GET request before date defined in Expires header, HTTPUrlCoonection witch enabled cache doesn't make request to server, but return data directly from cache, but I don't found way how to detect this situation.

Only way that I found is
System.currentTimeMillis() - Long.parseLong(getResponseHeader("X-Android-Received-Millis")) > 100;
But this depends on local time precision.
Will be much better if in response will be same special header which allow to recognize data from cache.
But it is probably problem of original AOSP implementation :-(

@swankjesse
Copy link

Can you use the cache's statistics reporting?

@tprochazka
Copy link
Author

I don't think so. Only that I will remember cache hit counter before request and compare it with state after request, if it will be incremented data are from cache, but I don't know if it is thread save, it would require same external synchronization which completely disallow parallel downloading :-(

@orrc
Copy link

orrc commented May 6, 2012

What's the issue with "local time precision"?

I'm sure Android's clock resolution is very high (i.e. better than 1 millisecond), or if you mean that the user (or network) can change the value of System.currentTimeMillis() at any point, then in any case you should be using Android's SystemClock.uptimeMillis().

@tprochazka
Copy link
Author

I mean that user can have turned off automatic time synchronization and can have wrong system time. And my only solution that I found is compare current system time with time-stamp X-Android-Received-Millis. I can't use SystemClock.uptimeMillis() because it is counted from system start and I can't compare it with unix timestamp. Much better would be if cache will add some flag that data are from cache. But it will work only this library, not in original android implementation :-(

@swankjesse
Copy link

Craig and I are working hard to keep this version and the android version in sync! But the Android 4.0 code is complete and we can't add any new behavior there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants