Ok, so I have this method, by which i grap html code from any input url:
private String GetURL(String f)throws Exception{ //return html code for input url f
String k=""; String l="";
URL url = new URL(f);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000); // 5 seconds
conn.setRequestMethod("GET");
conn.connect();
BufferedReader rd = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
while ((k = rd.readLine()) != null) {
l = l + k;
}
conn.disconnect();
return l;
}
It works fine for me. I am using it in an android application on its Main UI. So that when user launches the application, it fetches data from internet using above method and then displays it.
I want to know, is there any way that Java caches this information so that if it is retrieved too soon, it can return result from cache then going online again.
Because the problem is, whenever the user changes the layout, vertical to horizontal; the main display is reset and again user gets the progress bar prompt (which I've designed till the data is loaded). I want to avoid this without using any database complexity.
So want to know if Java offers any cache option automatically or not?