Julian
Julian

Reputation: 29

AFHTTPSessionManager with Cache Policy not working

Server sends cache header in response.

"Cache-Control": "max-age=120, public"

First I used NSURLRequestReturnCacheDataElseLoad with the AFHTTPRequestOperation.

By setting shared cache in AppDelegate and setting the NSURLRequestReturnCacheDataElseLoad in the NSUrlRequest.

It worked fine.

But when i tried to do the same with AFHTTPSessionManager by setting NSURLRequestReturnCacheDataElseLoad in the following ways,

1.request.session.configuration.requestCachePolicy

2.request.requestSerializer.cachePolicy

3.Overriding -(NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLResponse *, id, NSError *))completionHandler

Nothing seems to be working.

AFNetworking version - 2.5.1

Upvotes: 0

Views: 740

Answers (1)

Mantas Laurinavičius
Mantas Laurinavičius

Reputation: 951

I had the same problem and after hours of searching, I have found that AFHTTPSessionManager uses cookies to cache requests.

Simply deleted all cookies and it all worked.

NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (NSHTTPCookie *cookie in [storage cookies]) {
        [storage deleteCookie:cookie];
    }

Upvotes: 0

Related Questions