Hi,

I want to cache local files (images) so I cache a NSData using [NSURLCache storeCachedResponse] If I try to fetch it, the cachedResponseForRequest:request is always nil under 10.5

This works under 10.4.

I tried to create my own sharedURLCache, but it still doesn't work.

I use

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

  diskImage = [[NSImage alloc] initWithContentsOfFile:path];

  NSData    *data = [diskImage TIFFRepresentation];

  NSURL *cacheURL = [NSURL fileURLWithPath:aPath];

  NSURLResponse *response = [[[NSURLResponse alloc]
                              initWithURL:cacheURL
                              MIMEType:@"application/octet-stream"
                              expectedContentLength:[data length]
                              textEncodingName:nil] autorelease];
NSCachedURLResponse *cachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:response
                                          data:data
userInfo:[NSDictionary dictionary] storagePolicy:NSURLCacheStorageAllowed] autorelease];
  NSURLRequest *request = [NSURLRequest requestWithURL:cacheURL];
  [self storeCachedResponse:cachedResponse forRequest:request];

  cachedResponse = [self cachedResponseForRequest:request];
  if (cachedResponse) {
NSLog(@"cached data for %@ is %d", [[cachedResponse response] URL], [[cachedResponse data] length]);
  } else {
    NSLog(@"Cached response is NULL");
  }

What is the correct way to use NSURLCache with NSData on 10.5?

I have a test project available <http://coriolis.ch/dl/cache.zip> if anyone wants to have a look,

Thanks,
Stephan

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to