Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow forcing caching of non-cache-using requests.

  • Loading branch information...
commit 7cda7703c23379f09febe8ee02700399fe0b87af 1 parent 42ad9c7
BJ Homer authored June 06, 2012

Showing 2 changed files with 15 additions and 3 deletions. Show diff stats Hide diff stats

  1. 10  SDURLCache.h
  2. 8  SDURLCache.m
10  SDURLCache.h
@@ -38,6 +38,16 @@
38 38
  */
39 39
 @property (nonatomic, assign) BOOL ignoreMemoryOnlyStoragePolicy;
40 40
 
  41
+
  42
+/*
  43
+ * Allow caching responses for a request with a cache policy that ignores the local cache.
  44
+ * Usually, these responses don't need to be cached, because a request that ignores the cache
  45
+ * once is likely to do so every time it is used.
  46
+ * 
  47
+ * The default value is NO.
  48
+ */
  49
+@property (nonatomic, assign) BOOL allowCachingResponsesToNonCachedRequests;
  50
+
41 51
 /*
42 52
  * Returns a default cache director path to be used at cache initialization. The generated path directory
43 53
  * will be located in the application's cache directory and thus won't be synced by iTunes.
8  SDURLCache.m
@@ -652,9 +652,10 @@ - (id)initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger
652 652
 - (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NSURLRequest *)request {
653 653
     request = [SDURLCache canonicalRequestForRequest:request];
654 654
     
655  
-    if (request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData
656  
-        || request.cachePolicy == NSURLRequestReloadIgnoringLocalAndRemoteCacheData
657  
-        || request.cachePolicy == NSURLRequestReloadIgnoringCacheData) {
  655
+    if (!_allowCachingResponsesToNonCachedRequests &&
  656
+        (request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData
  657
+         || request.cachePolicy == NSURLRequestReloadIgnoringLocalAndRemoteCacheData
  658
+         || request.cachePolicy == NSURLRequestReloadIgnoringCacheData)) {
658 659
         // When cache is ignored for read, it's a good idea not to store the result as well as this option
659 660
         // have big chance to be used every times in the future for the same request.
660 661
         // NOTE: This is a change regarding default URLCache behavior
@@ -784,6 +785,7 @@ - (void)dealloc {
784 785
 
785 786
 @synthesize minCacheInterval = _minCacheInterval;
786 787
 @synthesize ignoreMemoryOnlyStoragePolicy = _ignoreMemoryOnlyStoragePolicy;
  788
+@synthesize allowCachingResponsesToNonCachedRequests = _allowCachingResponsesToNonCachedRequests;
787 789
 @synthesize diskCachePath = _diskCachePath;
788 790
 @synthesize diskCacheInfo = _diskCacheInfo;
789 791
 

0 notes on commit 7cda770

Please sign in to comment.
Something went wrong with that request. Please try again.