I am trying to cache data for offline usage without success. Below is my work so far.
//fetch news details
private void FetchHeadline(){
showDialog();
btnRefresh.setVisibility(View.GONE);
// We first check for cached request
Cache cache = AppController.getInstance().getRequestQueue().getCache();
Entry entry = cache.get(NEWS_URL);
if (entry != null) {
Log.e("", "babaaaaaaaaaaaaaaaaaaaaaaaa");
// fetch the data from cache
try {
String data = new String(entry.data, "UTF-8");
try {
parseJsonFeed(new JSONArray(data));
} catch (JSONException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
// making fresh volley request and getting json
JsonArrayRequest jsonReq = new JsonArrayRequest(
NEWS_URL + dbHelper.getAuth().getString(0), new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.e(TAG, "Response: " + response.toString());
if (response != null) {
parseJsonFeed(response);
}
hideDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
btnRefresh.setVisibility(View.VISIBLE);
hideDialog();
Log.e(TAG, "Response: " + error.getMessage());
try {
if (error.getMessage().equalsIgnoreCase("java.io.IOException: No authentication challenges found")){
moveToLoginActivity();}
}catch(Exception e){}
}
});
// Adding request to volley request queue
AppController.getInstance().addToRequestQueue(jsonReq);
}
I added the following to my .htaccess
with no success
<IfModule headers_module>
# 1 Month for most static assets
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
Header set Cache-Control "max-age=36000, public"
</filesMatch>
</IfModule>
Cache-Control →private, must-revalidate, max-age=36000, public
– Hayleyhayloft// Cache-Control takes precedence over an Expires header, even if both exist and Expires // is more restrictive. if (hasCacheControl) {
insideparseCacheHeaders
method ofHttpHeaderParser.java
file – Yurevindex.php
. Is it possible to specify some routes (e.g myserver.com/api/v1/cars) instead of the wholeindex.php
in the .htaccess file? – Hayleyhayloft