• 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
NSURL/NSURLHandle and caching
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSURL/NSURLHandle and caching


  • Subject: NSURL/NSURLHandle and caching
  • From: Tom Waters <email@hidden>
  • Date: Tue, 27 Nov 2001 19:22:35 -0800

i am struggling with NSURLHandle's propertyForKey: method.

i would expect that i could create an URL, get a handle to it, get the resource data, then query the properties to see things like the return codes, (for example 304 Not Modified and 404 Not Found).

if you use URLHandleUsingCache:YES this is indeed the behavior.

however, i need to NOT use the cache and make the request once each time.

the problem is, if I get an URLHandleUsingCache:NO, the subsequent propertyForKey: call does ANOTHER HTTP request. this time with HEAD instead of GET, but of course, that destroys the previous call's return code... this defeating the purpose!

i even tried using the "UsingCache:YES" version and calling [handle flushCachedData] afterwards, but it had no effect.

it's hard to describe what i'm trying to do, other than be a reasonable http client... here's some code torn out of my app, which may or may not make sense...

if you watch the server side of this (point it at say localhost), you can see that the propertyForKey calls are causing NSURL to do a subsequent HEAD call... if you change the NO to a YES, it does exactly one GET, and will never do it again, no matter if i flushCachedData or not.

- (void)get
{
NSURL *url = [NSURL URLWithString:@"http://www.apple.com/index.html";];
NSURLHandle *handle = [url URLHandleUsingCache:NO];
NSData *data;
id lastmod, lastmodString;
id code, reason;
[handle writeProperty:@"MyApp/1.0" forKey:@"User-Agent"];
[handle writeProperty:strlastmod forKey:@"If-Modified-Since"];
data = [handle resourceData];
code = [handle propertyForKey:NSHTTPPropertyStatusCodeKey];
reason = [handle propertyForKey:NSHTTPPropertyStatusReasonKey];
NSLog(@"%@ %@ %@", rel_path, code, reason);
lastmodString = [handle propertyForKey:@"Last-Modified"];
[handle flushCachedData];
}

does anyone (at apple?) have an opinion as to if i am doing something wrong, or i should just bail on NSURL/NSURLHandle and write my own client side using SmallSockets?


  • Follow-Ups:
    • Re: NSURL/NSURLHandle and caching
      • From: Dan Wood <email@hidden>
  • Prev by Date: Re: XML and NSCoder
  • Next by Date: Re: Finding Glyphs for String
  • Previous by thread: Editing one cell in a NSTableView
  • Next by thread: Re: NSURL/NSURLHandle and caching
  • Index(es):
    • Date
    • Thread