NSCachedURLResponse Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in iOS 2.0 and later.
Companion guide
Declared in
NSURLCache.h
Related sample code

Overview

An NSCachedURLResponse object represents a cached response to a URL request. It provides the server’s response metadata in the form of an NSURLResponse object, along with an NSData object containing the actual cached content data. Its storage policy determines whether the response should be cached on disk, in memory, or not at all.

Cached responses also contain a user info dictionary where you can store app-specific information about the cached item.

The NSURLCache class stores and retrieves instances of NSCachedURLResponse.

Tasks

Creating a Cached URL Response

Getting Cached URL Response Properties

Instance Methods

data

Returns the receiver’s cached data.

- (NSData *)data
Return Value

The receiver’s cached data.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSURLCache.h

initWithResponse:data:

Initializes an NSCachedURLResponse object.

- (id)initWithResponse:(NSURLResponse *)response data:(NSData *)data
Parameters
response

The response to cache.

data

The data to cache.

Return Value

The NSCachedURLResponse object, initialized using the given data.

Discussion

The cache storage policy is set to the default, NSURLCacheStorageAllowed, and the user info dictionary is set to nil.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSURLCache.h

initWithResponse:data:userInfo:storagePolicy:

Initializes an NSCachedURLResponse object.

- (id)initWithResponse:(NSURLResponse *)response data:(NSData *)data userInfo:(NSDictionary *)userInfo storagePolicy:(NSURLCacheStoragePolicy)storagePolicy
Parameters
response

The response to cache.

data

The data to cache.

userInfo

An optional dictionary of user information. May be nil.

storagePolicy

The storage policy for the cached response.

Return Value

The NSCachedURLResponse object, initialized using the given data.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSURLCache.h

response

Returns the NSURLResponse object associated with the receiver.

- (NSURLResponse *)response
Return Value

The NSURLResponse object associated with the receiver.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSURLCache.h

storagePolicy

Returns the receiver’s cache storage policy.

- (NSURLCacheStoragePolicy)storagePolicy
Return Value

The receiver’s cache storage policy.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSURLCache.h

userInfo

Returns the receiver’s user info dictionary.

- (NSDictionary *)userInfo
Return Value

An NSDictionary object containing the receiver’s user info, or nil if there is no such object.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSURLCache.h

Constants

NSURLCacheStoragePolicy

These constants specify the caching strategy used by an NSCachedURLResponse object.

typedef enum
{
   NSURLCacheStorageAllowed,
   NSURLCacheStorageAllowedInMemoryOnly,
   NSURLCacheStorageNotAllowed,
} NSURLCacheStoragePolicy;
Constants
NSURLCacheStorageAllowed

Specifies that storage in NSURLCache is allowed without restriction.

Important: iOS prior to version 5 ignores this cache policy, and instead treats it as NSURLCacheStorageAllowedInMemoryOnly.

Available in iOS 2.0 and later.

Declared in NSURLCache.h.

NSURLCacheStorageAllowedInMemoryOnly

Specifies that storage in NSURLCache is allowed; however storage should be restricted to memory only.

Available in iOS 2.0 and later.

Declared in NSURLCache.h.

NSURLCacheStorageNotAllowed

Specifies that storage in NSURLCache is not allowed in any fashion, either in memory or on disk.

Available in iOS 2.0 and later.

Declared in NSURLCache.h.

Availability
  • Available in iOS 2.0 and later.
Declared In
NSURLCache.h