• 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
Caching a local file using NSURLCache
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Caching a local file using NSURLCache


  • Subject: Caching a local file using NSURLCache
  • From: Stephan Burlot <email@hidden>
  • Date: Thu, 24 Apr 2008 00:14:31 +0200

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 (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


  • Follow-Ups:
    • Re: Caching a local file using NSURLCache
      • From: Jens Alfke <email@hidden>
    • Re: Caching a local file using NSURLCache
      • From: Michael Vannorsdel <email@hidden>
  • Prev by Date: Re: IB3 can't find my class
  • Next by Date: Re: "Safe" frameworks for privileged tools?
  • Previous by thread: Re: IB3 can't find my class
  • Next by thread: Re: Caching a local file using NSURLCache
  • Index(es):
    • Date
    • Thread