#gdg_kharkiv_center
HTTP Cache
Tips & Tricks (RFC 2616)
Alexander Sergienko
Senior Developer @ DataArt
#gdg_kharkiv_center
Why do I need to do this?
• Decrease traffic
• Increase loading speed
• Write less lines of code
• Offline mode
#gdg_kharkiv_center
How can I do this?
URL DATA CREATED_AT UPDATED_AT HASH_CODE
TEXT
BLOB TEXT TEXT TEXT
Enable HTTP cache
private void enableHttpResponseCache() {
try {
long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
File httpCacheDir = new File(getExternalCacheDir(), "http");
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (Exception httpResponseCacheNotAvailable) {
Log.d(TAG, "HTTP response cache is unavailable.");
}
}
#gdg_kharkiv_center
Will it work?
#gdg_kharkiv_center
Content validation headers
Request headers Response headers
If-Modified-Since (HTTP Date) Last-Modified (HTTP Date)
If-None-Match (Object Hash) ETag (Object Hash)
HTTP Date
RFC 822, updated by RFC 1123 Sun, 06 Nov 1994 08:49:37 GMT
RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT
RFC 822, updated by RFC 1123 Sun Nov 6 08:49:37 1994
#gdg_kharkiv_center
Check cache
#gdg_kharkiv_center
Cache managing headers
Request headers Response headers
Cache-Control ("no-cache" ;
"no-store"; "max-age" "="
delta-seconds ; "max-stale" "="
delta-seconds; "min-fresh" "="
delta-seconds ; "no-transform";
"only-if-cached")
Cache-Control ("public";
"private"; "no-cache"; "no-
store"; "no-transform"; "must-
revalidate"; "proxy-
revalidate"; "max-age" "="
delta-seconds; "s-maxage" "="
delta-seconds)
Pragma (no-cache)
Expires (HTTP Date)
#gdg_kharkiv_center
Alexander Sergienko
https://www.linkedin.com/in/alexandr-sergienko-3874b491
Q&A
Thank you!

Александр Сергиенко, Senior Android Developer, DataArt