Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

NSURLCacheStoragePolicy #125

Closed
wants to merge 46 commits into from

2 participants

@zbowling

I added support for changing the NSURLCacheStoragePolicy.

You only need to cherry pick seatme/AFNetworking@e2e14cc. Hopefully that should apply cleanly. Our versions are growing a little divergent as I build on our changes but this one feature may apply cleanly upstream so I wanted to make note of it before I continue to move forward.

zbowling and others added some commits
@zbowling zbowling async fixes. changes for json d3af887
@zbowling zbowling I fixed something e1d89f8
@zbowling zbowling small change' dd84bad
@zbowling zbowling better foundation json support ef5bf73
@zbowling zbowling Merge branch 'merge_foundation_json' of github.com:seatme/AFNetworking
Conflicts:
	AFNetworking/AFHTTPClient.m
	AFNetworking/AFHTTPRequestOperation.m
	AFNetworking/AFJSONRequestOperation.m
	AFNetworking/AFXMLRequestOperation.m
	AFNetworking/NSString+AFNetworking.h
	Example/Classes/AFGowallaAPIClient.h
	Mac Example/AppDelegate.h
	Mac Example/AppDelegate.m
	Mac Example/Classes/AFGowallaAPIClient.h
	iOS Example/Classes/AFGowallaAPIClient.h
521fd35
@zbowling zbowling brought to much over in the merge d55245e
@zbowling zbowling better JSON support 2c0ef65
@zbowling zbowling better idea e42d89d
@zbowling zbowling class custer method 23ac76c
@zbowling zbowling should be self d6ffe69
@zbowling zbowling much much better ec9a8b0
@zbowling zbowling moved this to the same file 54f90d4
@zbowling zbowling moved this to the same file b3cf84e
@zbowling zbowling merged in upstream changes 6c1cd78
@zbowling zbowling Merge branch 'experimental-0.8' of https://github.com/gowalla/AFNetwo…
…rking

Conflicts:
	AFNetworking/AFHTTPClient.m
	AFNetworking/AFHTTPRequestOperation.h
	AFNetworking/AFHTTPRequestOperation.m
	AFNetworking/AFJSONRequestOperation.h
	AFNetworking/AFJSONRequestOperation.m
	AFNetworking/AFPropertyListRequestOperation.h
	AFNetworking/AFPropertyListRequestOperation.m
	AFNetworking/AFXMLRequestOperation.h
	AFNetworking/AFXMLRequestOperation.m
e5e6f97
@zbowling zbowling fixed a lot of various changes after the merge. much better bb96088
@zbowling zbowling forgot to mark this as concurrent. a3c3322
@zbowling zbowling self is never delegate. don't unset the delegate if someone else want…
…ed to be the delegate.
1511a45
@zbowling zbowling no such thing as an error here. 1cfe657
@zbowling zbowling comments. 70fd2d8
@zbowling zbowling dead property 9834ad4
@zbowling zbowling comments 932d710
@zbowling zbowling Foundation json should be last. 2a939e5
@zbowling zbowling conventions and leaks 9a6d541
@zbowling zbowling Merge branch 'experimental-0.8' of https://github.com/gowalla/AFNetwo…
…rking

Conflicts:
	AFNetworking/AFJSONUtilities.h
bcbf99c
@zbowling zbowling Merge branch 'experimental-0.8' of https://github.com/gowalla/AFNetwo…
…rking

Conflicts:
	AFNetworking/AFHTTPClient.m
a0a83a6
@zbowling zbowling fix path of this. a9e645d
@zbowling zbowling Pull this change in from other branch daaba29
@zbowling zbowling Merge github.com:seatme/AFNetworking b4335c0
@mattt mattt Updating README to point to new AFNetworking URL (https://github.com/… 920b01d
@zbowling zbowling Fix memory leak ccfcd43
@zbowling zbowling Merge branch 'master' of github.com:zbowling/AFNetworking e86aa7a
@zbowling zbowling Merge branch 'master' of git://github.com/gowalla/AFNetworking
Conflicts:
	AFNetworking/AFHTTPClient.m
	AFNetworking/AFImageRequestOperation.h
	AFNetworking/AFImageRequestOperation.m
	AFNetworking/AFJSONRequestOperation.h
	AFNetworking/AFXMLRequestOperation.m
1d12038
@zbowling zbowling much better solution 9088768
@zbowling zbowling change upstream and merge 11057cf
@zbowling zbowling fix a few lingering issues after the merge b3fb0bb
@zbowling zbowling new README 695ea9c
@zbowling zbowling New README for specifying the changes in our fork. 8dd9494
@zbowling zbowling Update README.md e746bf4
@zbowling zbowling Remove silly, overly paranoid code in setCompletionBlock and let the …
…parent have a say in the isReady process so it can check dependent NSOperations.
23ca8b4
@zbowling zbowling add support for iOS multitasking. 16b5839
@zbowling zbowling Merge branch 'master' of github.com:seatme/AFNetworking f1cb7aa
@zbowling zbowling Update README.md 87feccd
@zbowling zbowling move multitasking support up to AFHTTPURLRequest d56f873
@zbowling zbowling Merge branch 'master' of github.com:seatme/AFNetworking 552e0cf
@zbowling zbowling add cache policy support e2e14cc
@mattt

As I understand it, HTTP facilitates contracts between client and server, which are communicated through headers. As per the specifications for the Cache-Control header:

The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.

To override this, then, is to violate that contract, which I can only imagine leading to unexpected behavior somewhere down the line. While the architecture of AFURLConnectionOperation make it straightforward to manually define this behavior (by overriding the delegate method in a subclass), I do not think that it's especially useful to better enable behavior that violates HTTP expectations.

AFNetworking already supports NSURLCacheStoragePolicy by correctly using NSURLConnection. Any server responses that instruct to cache itself on the client will already do so, into NSURLCache.

@zbowling

NSURLRequestCachePolicy is different from NSURLCacheStoragePolicy. NSURLRequestCache policy works on the NSURLConnection and NSURLCacheStoragePolicy works on the NSURLCache object.

NSURLRequestCachePolicy controls a few headers like Cache-Control. NSURLCacheStoragePolicy controls how you want to persist the response if the NSURLConnection thinks the response can be cached at all.

How you handle the Cache-Control header is entirely different from how you persist the response to locally. The Cache-Control header documentation refers to everyone along the chain (like proxy servers and reverse caches) but it has nothing to do with me as the client and how I cache the final response. That is entirely different.

If the response says I can cache, there is no expectation in HTTP that I will or that I will use any kind of real persistence when I do.

That is why there are two options in NSURLConnection. One controls how you send the Cache-Policy header, and the other handles persistance of the response. By default this is always NSURLCacheStorageAllowed.

The issue is that NSURLCache on iOS is extremely limited anyways. By default iOS only does in memory caching even though NSCachedURLResponse tells NSURLCache to use NSURLCacheStorageAllowed and not NSURLCacheStorageAllowedInMemoryOnly. By default iOS doesn't actually persist much of anything.

However, the great thing is with NSURLCache you can register a different shared NSURLCache, like SDURLCache or our soon to be released implementation, that will cache to disk in a very optimal pattern (almost like NSURLCache does on OS X).

They do this to save people from filling up space or generally wearing down the flash memory. If you are careful though there is nothing wrong with disk based caching and may improve your app's experience doing it depending on the kind of app you have. In our case we have a lot of images and want them to be cached.

Having this option allows you to finer grained control on the Mac and on iOS (if you are using a NSURLCache subclass) to keep the existing behavior or persist it longer or to just not persist at all.

@mattt mattt closed this
@zbowling

Why was this closed? Don't understand. Not that it maters much but curious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 22, 2011
  1. @zbowling

    async fixes. changes for json

    zbowling authored
Commits on Sep 26, 2011
  1. @zbowling

    I fixed something

    zbowling authored
Commits on Oct 6, 2011
  1. @zbowling

    small change'

    zbowling authored
Commits on Oct 16, 2011
  1. @zbowling
Commits on Oct 18, 2011
  1. @zbowling

    Merge branch 'merge_foundation_json' of github.com:seatme/AFNetworking

    zbowling authored
    Conflicts:
    	AFNetworking/AFHTTPClient.m
    	AFNetworking/AFHTTPRequestOperation.m
    	AFNetworking/AFJSONRequestOperation.m
    	AFNetworking/AFXMLRequestOperation.m
    	AFNetworking/NSString+AFNetworking.h
    	Example/Classes/AFGowallaAPIClient.h
    	Mac Example/AppDelegate.h
    	Mac Example/AppDelegate.m
    	Mac Example/Classes/AFGowallaAPIClient.h
    	iOS Example/Classes/AFGowallaAPIClient.h
  2. @zbowling
Commits on Oct 21, 2011
  1. @zbowling

    better JSON support

    zbowling authored
  2. @zbowling

    better idea

    zbowling authored
  3. @zbowling

    class custer method

    zbowling authored
  4. @zbowling

    should be self

    zbowling authored
  5. @zbowling

    much much better

    zbowling authored
  6. @zbowling

    moved this to the same file

    zbowling authored
  7. @zbowling

    moved this to the same file

    zbowling authored
Commits on Nov 8, 2011
  1. @zbowling

    merged in upstream changes

    zbowling authored
  2. @zbowling

    Merge branch 'experimental-0.8' of https://github.com/gowalla/AFNetwo…

    zbowling authored
    …rking
    
    Conflicts:
    	AFNetworking/AFHTTPClient.m
    	AFNetworking/AFHTTPRequestOperation.h
    	AFNetworking/AFHTTPRequestOperation.m
    	AFNetworking/AFJSONRequestOperation.h
    	AFNetworking/AFJSONRequestOperation.m
    	AFNetworking/AFPropertyListRequestOperation.h
    	AFNetworking/AFPropertyListRequestOperation.m
    	AFNetworking/AFXMLRequestOperation.h
    	AFNetworking/AFXMLRequestOperation.m
  3. @zbowling
  4. @zbowling
  5. @zbowling
  6. @zbowling
  7. @zbowling

    comments.

    zbowling authored
  8. @zbowling

    dead property

    zbowling authored
  9. @zbowling

    comments

    zbowling authored
  10. @zbowling
  11. @zbowling

    conventions and leaks

    zbowling authored
  12. @zbowling

    Merge branch 'experimental-0.8' of https://github.com/gowalla/AFNetwo…

    zbowling authored
    …rking
    
    Conflicts:
    	AFNetworking/AFJSONUtilities.h
Commits on Nov 9, 2011
  1. @zbowling

    Merge branch 'experimental-0.8' of https://github.com/gowalla/AFNetwo…

    zbowling authored
    …rking
    
    Conflicts:
    	AFNetworking/AFHTTPClient.m
  2. @zbowling

    fix path of this.

    zbowling authored
  3. @zbowling
  4. @zbowling
Commits on Nov 11, 2011
  1. @mattt
Commits on Nov 16, 2011
  1. @zbowling

    Fix memory leak

    zbowling authored
  2. @zbowling
  3. @zbowling

    Merge branch 'master' of git://github.com/gowalla/AFNetworking

    zbowling authored
    Conflicts:
    	AFNetworking/AFHTTPClient.m
    	AFNetworking/AFImageRequestOperation.h
    	AFNetworking/AFImageRequestOperation.m
    	AFNetworking/AFJSONRequestOperation.h
    	AFNetworking/AFXMLRequestOperation.m
  4. @zbowling

    much better solution

    zbowling authored
Commits on Nov 22, 2011
  1. @zbowling

    change upstream and merge

    zbowling authored
  2. @zbowling
  3. @zbowling

    new README

    zbowling authored
  4. @zbowling
  5. @zbowling

    Update README.md

    zbowling authored
  6. @zbowling

    Remove silly, overly paranoid code in setCompletionBlock and let the …

    zbowling authored
    …parent have a say in the isReady process so it can check dependent NSOperations.
  7. @zbowling
  8. @zbowling
  9. @zbowling

    Update README.md

    zbowling authored
Commits on Nov 23, 2011
  1. @zbowling
  2. @zbowling
  3. @zbowling

    add cache policy support

    zbowling authored
Something went wrong with that request. Please try again.