SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Downloaden Sie, um offline zu lesen
Caching. API.
HTTP 1.1 (RFC 2616)
1
Caching tasks:
1. Activating content upload;
2. Decreasing traffic;
3. Simplifying code (reduction of complexity and size);
4. Making possible to look through content offline (that was browsed before).
2
1. *Create database with tables for every rendering entity, and tables synchronization.
2. *Create database with one table and two fields: URL-request and response.
3. Enable HTTP cache (native or third-party).
* should write validation logic request/response
How to create cache using HTTP Restful:
HTTP & RESTFul
The more understandable - the better!
3
1. GET - Receiving data, an element or a list
Potential entries > 50 ? pagination : that’ll do;
Size of JSON list > 100 Kb ? pagination : that’ll do.
2. PUT - updating entry(ies).
3. POST - creating entry(ies).
4. DELETE - deleting entry(ies).
5. HEAD - getting headers in response, without body.
------------------------------------------------------------
Examples of caching URL(GET) requests:
http://blalala.com/api/category/1/articles
http://blalala.com/api/category/1/articles?offset=0&count=20
HTTP 1.1 Content validators
4
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 850, obsoleted by RFC 1036 Sunday, 06-Nov-94 08:49:37 GMT
ANSI C's asctime() format Sun Nov 6 08:49:37 1994
Server
First request
200 code, headers and
response body
200 code, headers and response
body, 304 code and headers
Second request
HTTP 1.1 Cache managing
5
Request headers Response headers
Expires (HTTP Date)
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)
HTTP 1.1 Cache-Control
6
● max-age=[seconds] — describes maximum time of continuing content to be fresh.
● max-stale=[seconds] — describes period of time, when it is better to put scale
content back, without request for server.
● s-maxage=[seconds] — like max-age, but is used to intermediate cache.
● public — marks requests as publicly available.
● private — is caching only on an end device.
● no-cache — makes cache to send request on a source server every time for
validation.
● no-store — doesn’t let cache save content copy, at no point.
● must-revalidate — updates content even if there is available information in cache.
● proxy-revalidate — like must-revalidate, but is used to proxy.
Android Setup
7
After the launching Android 4.0 version the HttpResponseCache class has become available, it
runs together with HttpURLConnection. Also OkHttp and Volley caches can be used (cache
operating speed is approximately the same).
You can enable cache in such way:
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.");
}
}
iOS Setup
8
You can enable cache in app delegate, that runs together with NSURLRequest:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions {
...
NSURLCache *myURLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 *
1024/*in bytes*/diskCapacity:20 * 1024 * 1024/*in bytes*/ diskPath:nil/*@"my folder in
default cache folder"*/];
[NSURLCache setSharedURLCache:myURLCache];
...
return YES;
}
For solving situations, which can’t be taken into a protocol, you can use another NSURLRequestCachePolicy:
1. NSURLRequestUseProtocolCachePolicy = 0, - default, is used for caching following the data from headers requests.
2. NSURLRequestReloadIgnoringLocalCacheData = 1, - is used for the force data loading.
3. NSURLRequestReturnCacheDataElseLoad = 2, - data on demand are got from cache (without sending a request on
server for checking its truth).
4. NSURLRequestReturnCacheDataDontLoad = 3, - data are got only from cache, and can be used in case of no Internet
connection.
Conclusion
9
1. To gain insight on the whole structure can’t be easy, but it is
worth it.
2. Error detection is challenging (the appearance of any unknown
header can change the process of caching).
3. It is incomprehensible how the third-party libraries work with
cache (especially iOS: AFNetworking, RestKit...), that is a matter
of argument on this seminar.
Alexander Sergienko
alex.khrv@gmail.com
skype: lex_sergienko_s

Weitere ähnliche Inhalte

Was ist angesagt?

Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014
Özgür Umut Vurgun
 
glance replicator
glance replicatorglance replicator
glance replicator
irix_jp
 
What I learned from FluentConf and then some
What I learned from FluentConf and then someWhat I learned from FluentConf and then some
What I learned from FluentConf and then some
Ohad Kravchick
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres Monitoring
Denish Patel
 

Was ist angesagt? (20)

Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014
 
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018
 
Containers: What are they, Really?
Containers: What are they, Really?Containers: What are they, Really?
Containers: What are they, Really?
 
10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators  10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
 
glance replicator
glance replicatorglance replicator
glance replicator
 
PostgreSQL Replication Tutorial
PostgreSQL Replication TutorialPostgreSQL Replication Tutorial
PostgreSQL Replication Tutorial
 
StackExchange.redis
StackExchange.redisStackExchange.redis
StackExchange.redis
 
Data warehouse on Kubernetes - gentle intro to Clickhouse Operator, by Robert...
Data warehouse on Kubernetes - gentle intro to Clickhouse Operator, by Robert...Data warehouse on Kubernetes - gentle intro to Clickhouse Operator, by Robert...
Data warehouse on Kubernetes - gentle intro to Clickhouse Operator, by Robert...
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisation
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
 
What I learned from FluentConf and then some
What I learned from FluentConf and then someWhat I learned from FluentConf and then some
What I learned from FluentConf and then some
 
To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)To Hire, or to train, that is the question (Percona Live 2014)
To Hire, or to train, that is the question (Percona Live 2014)
 
Exploring, understanding and monitoring macOS activity with osquery
Exploring, understanding and monitoring macOS activity with osqueryExploring, understanding and monitoring macOS activity with osquery
Exploring, understanding and monitoring macOS activity with osquery
 
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
 
Advanced Postgres Monitoring
Advanced Postgres MonitoringAdvanced Postgres Monitoring
Advanced Postgres Monitoring
 
HBaseCon 2013: OpenTSDB at Box
HBaseCon 2013: OpenTSDB at BoxHBaseCon 2013: OpenTSDB at Box
HBaseCon 2013: OpenTSDB at Box
 
Node.js
Node.jsNode.js
Node.js
 

Ähnlich wie Caching. api. http 1.1

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

Ähnlich wie Caching. api. http 1.1 (20)

cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
Efficient HTTP Apis
Efficient HTTP ApisEfficient HTTP Apis
Efficient HTTP Apis
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sites
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Study
 
Freezer - Vietnam OpenStack Technical Meetup #12
Freezer - Vietnam OpenStack Technical Meetup #12Freezer - Vietnam OpenStack Technical Meetup #12
Freezer - Vietnam OpenStack Technical Meetup #12
 
Ece2013 Java Advanced Memorymanagement
Ece2013 Java Advanced MemorymanagementEce2013 Java Advanced Memorymanagement
Ece2013 Java Advanced Memorymanagement
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018Elastic101tutorial Percona Live Europe 2018
Elastic101tutorial Percona Live Europe 2018
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
 
06 integrate elasticsearch
06 integrate elasticsearch06 integrate elasticsearch
06 integrate elasticsearch
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Lua tech talk
Lua tech talkLua tech talk
Lua tech talk
 
HTTP Caching and PHP
HTTP Caching and PHPHTTP Caching and PHP
HTTP Caching and PHP
 
Александр Сергиенко, Senior Android Developer, DataArt
Александр Сергиенко, Senior Android Developer, DataArtАлександр Сергиенко, Senior Android Developer, DataArt
Александр Сергиенко, Senior Android Developer, DataArt
 
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
 
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
 
AWS Java SDK @ scale
AWS Java SDK @ scaleAWS Java SDK @ scale
AWS Java SDK @ scale
 
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable CacheMobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
 

Mehr von Artjoker Digital

Mehr von Artjoker Digital (8)

Selling email marketing
Selling email marketingSelling email marketing
Selling email marketing
 
How to sell via the website
How to sell via the websiteHow to sell via the website
How to sell via the website
 
Context advertising
Context advertisingContext advertising
Context advertising
 
Content marketing.ppt
Content marketing.pptContent marketing.ppt
Content marketing.ppt
 
Blogs: how to write cool articles
Blogs: how to write cool articlesBlogs: how to write cool articles
Blogs: how to write cool articles
 
Efficient development theory
Efficient development theoryEfficient development theory
Efficient development theory
 
Json parsers comparison
Json parsers comparisonJson parsers comparison
Json parsers comparison
 
Retro vs volley (2)
Retro vs volley (2)Retro vs volley (2)
Retro vs volley (2)
 

Kürzlich hochgeladen

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Kürzlich hochgeladen (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 

Caching. api. http 1.1

  • 1. Caching. API. HTTP 1.1 (RFC 2616) 1
  • 2. Caching tasks: 1. Activating content upload; 2. Decreasing traffic; 3. Simplifying code (reduction of complexity and size); 4. Making possible to look through content offline (that was browsed before). 2 1. *Create database with tables for every rendering entity, and tables synchronization. 2. *Create database with one table and two fields: URL-request and response. 3. Enable HTTP cache (native or third-party). * should write validation logic request/response How to create cache using HTTP Restful:
  • 3. HTTP & RESTFul The more understandable - the better! 3 1. GET - Receiving data, an element or a list Potential entries > 50 ? pagination : that’ll do; Size of JSON list > 100 Kb ? pagination : that’ll do. 2. PUT - updating entry(ies). 3. POST - creating entry(ies). 4. DELETE - deleting entry(ies). 5. HEAD - getting headers in response, without body. ------------------------------------------------------------ Examples of caching URL(GET) requests: http://blalala.com/api/category/1/articles http://blalala.com/api/category/1/articles?offset=0&count=20
  • 4. HTTP 1.1 Content validators 4 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 850, obsoleted by RFC 1036 Sunday, 06-Nov-94 08:49:37 GMT ANSI C's asctime() format Sun Nov 6 08:49:37 1994 Server First request 200 code, headers and response body 200 code, headers and response body, 304 code and headers Second request
  • 5. HTTP 1.1 Cache managing 5 Request headers Response headers Expires (HTTP Date) 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)
  • 6. HTTP 1.1 Cache-Control 6 ● max-age=[seconds] — describes maximum time of continuing content to be fresh. ● max-stale=[seconds] — describes period of time, when it is better to put scale content back, without request for server. ● s-maxage=[seconds] — like max-age, but is used to intermediate cache. ● public — marks requests as publicly available. ● private — is caching only on an end device. ● no-cache — makes cache to send request on a source server every time for validation. ● no-store — doesn’t let cache save content copy, at no point. ● must-revalidate — updates content even if there is available information in cache. ● proxy-revalidate — like must-revalidate, but is used to proxy.
  • 7. Android Setup 7 After the launching Android 4.0 version the HttpResponseCache class has become available, it runs together with HttpURLConnection. Also OkHttp and Volley caches can be used (cache operating speed is approximately the same). You can enable cache in such way: 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."); } }
  • 8. iOS Setup 8 You can enable cache in app delegate, that runs together with NSURLRequest: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { ... NSURLCache *myURLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024/*in bytes*/diskCapacity:20 * 1024 * 1024/*in bytes*/ diskPath:nil/*@"my folder in default cache folder"*/]; [NSURLCache setSharedURLCache:myURLCache]; ... return YES; } For solving situations, which can’t be taken into a protocol, you can use another NSURLRequestCachePolicy: 1. NSURLRequestUseProtocolCachePolicy = 0, - default, is used for caching following the data from headers requests. 2. NSURLRequestReloadIgnoringLocalCacheData = 1, - is used for the force data loading. 3. NSURLRequestReturnCacheDataElseLoad = 2, - data on demand are got from cache (without sending a request on server for checking its truth). 4. NSURLRequestReturnCacheDataDontLoad = 3, - data are got only from cache, and can be used in case of no Internet connection.
  • 9. Conclusion 9 1. To gain insight on the whole structure can’t be easy, but it is worth it. 2. Error detection is challenging (the appearance of any unknown header can change the process of caching). 3. It is incomprehensible how the third-party libraries work with cache (especially iOS: AFNetworking, RestKit...), that is a matter of argument on this seminar. Alexander Sergienko alex.khrv@gmail.com skype: lex_sergienko_s