{"action":"created","issue":{"url":"https://api.github.com/repos/amitshekhariitbhu/Fast-Android-Networking/issues/127","repository_url":"https://api.github.com/repos/amitshekhariitbhu/Fast-Android-Networking","labels_url":"https://api.github.com/repos/amitshekhariitbhu/Fast-Android-Networking/issues/127/labels{/name}","comments_url":"https://api.github.com/repos/amitshekhariitbhu/Fast-Android-Networking/issues/127/comments","events_url":"https://api.github.com/repos/amitshekhariitbhu/Fast-Android-Networking/issues/127/events","html_url":"https://github.com/amitshekhariitbhu/Fast-Android-Networking/issues/127","id":232134442,"number":127,"title":"Setup cache by custom Okhttp","user":{"login":"mdtuyen","id":10714532,"avatar_url":"https://avatars1.githubusercontent.com/u/10714532?v=3","gravatar_id":"","url":"https://api.github.com/users/mdtuyen","html_url":"https://github.com/mdtuyen","followers_url":"https://api.github.com/users/mdtuyen/followers","following_url":"https://api.github.com/users/mdtuyen/following{/other_user}","gists_url":"https://api.github.com/users/mdtuyen/gists{/gist_id}","starred_url":"https://api.github.com/users/mdtuyen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdtuyen/subscriptions","organizations_url":"https://api.github.com/users/mdtuyen/orgs","repos_url":"https://api.github.com/users/mdtuyen/repos","events_url":"https://api.github.com/users/mdtuyen/events{/privacy}","received_events_url":"https://api.github.com/users/mdtuyen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-05-30T03:28:41Z","updated_at":"2017-06-03T03:55:13Z","closed_at":null,"body":"Hi,\r\n\r\nI read document of this library about caching:\r\nhttps://amitshekhariitbhu.github.io/Fast-Android-Networking/caching.html\r\n\r\nI see that I can control cache by some function as:\r\n.doNotCacheResponse()\r\n .getResponseOnlyIfCached()\r\n.getResponseOnlyFromNetwork()\r\n .setMaxAgeCacheControl(0, TimeUnit.SECONDS)\r\n.setMaxStaleCacheControl(365, TimeUnit.SECONDS)\r\n\r\nThat mean I need put these function to each request.\r\nNow, I' want to custom Okhttp to work with all request. This is my custom:\r\n ```\r\nAndroidNetworking.initialize(getApplicationContext(), new OkHttpClient.Builder()\r\n                .cookieJar(new CookieJar() {\r\n                    private final HashMap<String, List<Cookie>> cookieStore = new HashMap<>();\r\n\r\n                    @Override\r\n                    public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {\r\n                        cookieStore.put(url.host(), cookies);\r\n                    }\r\n\r\n                    @Override\r\n                    public List<Cookie> loadForRequest(HttpUrl url) {\r\n                        List<Cookie> cookies = cookieStore.get(url.host());\r\n                        return cookies != null ? cookies : new ArrayList<Cookie>();\r\n                    }\r\n                })\r\n                .addNetworkInterceptor(new Interceptor() {\r\n                    @Override\r\n                    public Response intercept(Chain chain) throws IOException {\r\n                        Request request = chain.request();\r\n                        if (!NetworkState.networkConnected(Apploader.context)) {\r\n                            request = request.newBuilder()\r\n                                    .cacheControl(CacheControl.FORCE_CACHE)\r\n                                    .build();\r\n                        }\r\n                        Response response = chain.proceed(request);\r\n\r\n                        if (NetworkState.networkConnected(Apploader.context)) {\r\n                            String cacheControl = request.cacheControl().toString();\r\n                            response = response.newBuilder()\r\n                                    .removeHeader(\"Pragma\")\r\n                                    .removeHeader(\"Cache-Control\")\r\n                                    .header(\"Cache-Control\", cacheControl)\r\n                                    .build();\r\n                        } else {\r\n                            int maxStale = 60 * 60 * 24 * 7;\r\n                            response = response.newBuilder()\r\n                                    .removeHeader(\"Pragma\")\r\n                                    .removeHeader(\"Cache-Control\")\r\n                                    .header(\"Cache-Control\", \"public, only-if-cached, max-stale=\" + maxStale)\r\n                                    .build();\r\n                        }\r\n                        return response;\r\n                    }\r\n                })\r\n                .cache(new Cache(new File(getCacheDir(), \"responses\"), 20 * 1024 * 1024))\r\n                .connectTimeout(120, TimeUnit.SECONDS)\r\n                .readTimeout(120, TimeUnit.SECONDS)\r\n                .writeTimeout(120, TimeUnit.SECONDS)\r\n                .build());\r\n```\r\n\r\nThat is config I used in Retrofit.\r\nNow it not work.\r\n"},"comment":{"url":"https://api.github.com/repos/amitshekhariitbhu/Fast-Android-Networking/issues/comments/305948991","html_url":"https://github.com/amitshekhariitbhu/Fast-Android-Networking/issues/127#issuecomment-305948991","issue_url":"https://api.github.com/repos/amitshekhariitbhu/Fast-Android-Networking/issues/127","id":305948991,"user":{"login":"mdtuyen","id":10714532,"avatar_url":"https://avatars1.githubusercontent.com/u/10714532?v=3","gravatar_id":"","url":"https://api.github.com/users/mdtuyen","html_url":"https://github.com/mdtuyen","followers_url":"https://api.github.com/users/mdtuyen/followers","following_url":"https://api.github.com/users/mdtuyen/following{/other_user}","gists_url":"https://api.github.com/users/mdtuyen/gists{/gist_id}","starred_url":"https://api.github.com/users/mdtuyen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdtuyen/subscriptions","organizations_url":"https://api.github.com/users/mdtuyen/orgs","repos_url":"https://api.github.com/users/mdtuyen/repos","events_url":"https://api.github.com/users/mdtuyen/events{/privacy}","received_events_url":"https://api.github.com/users/mdtuyen/received_events","type":"User","site_admin":false},"created_at":"2017-06-03T03:55:13Z","updated_at":"2017-06-03T03:55:13Z","body":"Hi @amitshekhariitbhu , did you check it ?"}}
{"actor":{"display_login":"mdtuyen"}}