Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignoreMemoryOnlyStoragePolicy is NO by default #1

Open
youboox opened this issue Nov 29, 2011 · 0 comments
Open

ignoreMemoryOnlyStoragePolicy is NO by default #1

youboox opened this issue Nov 29, 2011 · 0 comments

Comments

@youboox
Copy link

youboox commented Nov 29, 2011

Hi,

I just tried SDURLCache and it looks just great. But it seems disk caching is off by default (contrary to what is saif in the comments on the header).

Step to reproduce the problem :

  1. Create the cache in the appDelegate
SDURLCache *urlCache = [[SDURLCache alloc] initWithMemoryCapacity:1024*1024   // 1MB mem cache
                                                     diskCapacity:1024*1024*1000 // 1GB disk cache
                                                         diskPath:[SDURLCache defaultCachePath]];
[NSURLCache setSharedURLCache:urlCache];
[urlCache release];
  1. Call a request with AFNetWorking :
 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:fileUrl]];
 [request setCachePolicy:NSURLCacheStorageAllowed];
 NSCachedURLResponse* cachedMenuResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];

if(cachedMenuResponse==nil) {
    AFURLConnectionOperation *operation = [[AFURLConnectionOperation alloc] initWithRequest:request];
  1. Answer is never cached, setting breakpoint in SDURLCache.m line 453 : _ignoreMemoryOnlyStoragePolicy = NO
- (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NSURLRequest *)request {
.
.
.
NSURLCacheStoragePolicy storagePolicy = cachedResponse.storagePolicy;
if ((storagePolicy == NSURLCacheStorageAllowed || (storagePolicy == NSURLCacheStorageAllowedInMemoryOnly && _ignoreMemoryOnlyStoragePolicy))
    && [cachedResponse.response isKindOfClass:[NSHTTPURLResponse self]]
    && cachedResponse.data.length < self.diskCapacity) {

Solution :

I solved the problem by forcing ignoreMemoryOnlyStoragePolicy to YES :

 SDURLCache *urlCache = [[SDURLCache alloc] initWithMemoryCapacity:1024*1024   // 1MB mem cache
                                                     diskCapacity:1024*1024*1000 // 1GB disk cache
                                                         diskPath:[SDURLCache defaultCachePath]];
 urlCache.ignoreMemoryOnlyStoragePolicy = YES;
 [NSURLCache setSharedURLCache:urlCache];
 [urlCache release];

I think either the comments on the header are wrong or there is a bug.

Thanks,
Vincent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant