• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trouble with NSURLCache
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble with NSURLCache


  • Subject: Trouble with NSURLCache
  • From: Stephan Burlot <email@hidden>
  • Date: Sat, 10 Nov 2007 14:04:24 +0100

Hi,

Can somebody explain whats's wrong here? I cache a NSData using [NSURLCache storeCachedResponse] but if I try to fetch it immediately (or after a while), the cachedResponseForRequest:request is always nil?

I came on this problem while trying to understand why my app didnt cache the data on Leopard (but works OK on Tiger).
I tried to create my own cache, but it still doesnt work.


I use

NSString *path = [NSString stringWithString:@"/Library/Desktop Pictures/Nature/Clown Fish.jpg"];
NSImage* diskImage;


diskImage = [[NSImage alloc] initWithContentsOfFile:path];
[[NSURLCache sharedURLCache] cacheData:[diskImage TIFFRepresentation] forPath:path];


to cache the data, and I add this category to NSURLCache:
The code comes from a post from Dan Wood.

- (void) cacheData:(NSData *)aData forPath:(NSString *)aPath;
{

NSURL *cacheURL = [NSURL fileURLWithPath:aPath];
NSURLResponse *response = [[[NSURLResponse alloc]
initWithURL:cacheURL
MIMEType:@"application/octet-stream"
expectedContentLength:[aData length]
textEncodingName:nil] autorelease];
NSCachedURLResponse *cachedResponse = [[[NSCachedURLResponse alloc]
initWithResponse:response data:aData userInfo:nil storagePolicy:NSURLCacheStorageAllowed] autorelease];
NSURLRequest *request = [NSURLRequest requestWithURL:cacheURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:300];
[self storeCachedResponse:cachedResponse forRequest:request];
if ([self cachedResponseForRequest:request] == NULL) {
NSLog(@"Something wrong here.");
}
}


Thanks,
Stephan

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSView / Drag and Drop: Any API or constants to detect the start of a drag?
  • Next by Date: Re: NSView / Drag and Drop: Any API or constants to detect the start of a drag?
  • Previous by thread: re:[Core Data] Lightweight Objects
  • Next by thread: IB 3.0
  • Index(es):
    • Date
    • Thread