NSURLCache 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 |
Overview
NSURLCache implements the caching of responses to URL load requests by mapping NSURLRequest objects to NSCachedURLResponse objects. It is a composite of an in-memory and an on-disk cache.
Methods are provided to manipulate the sizes of each of these caches as well as to control the path on disk to use for persistent storage of cache data.
Tasks
Getting and Setting Shared Cache
Creating a New Cache Object
Getting and Storing Cached Objects
Removing Cached Objects
Getting and Setting On-disk Cache Properties
Getting and Setting In-memory Cache Properties
Class Methods
setSharedURLCache:
Sets the shared NSURLCache instance to a specified cache object.
Parameters
- cache
The cache object to use as the shared cache object.
Discussion
An application that has special caching requirements or constraints should use this method to specify an NSURLCache instance with customized cache settings. The application should do so before any calls to the sharedURLCache method.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hsharedURLCache
Returns the shared NSURLCache instance.
Return Value
The shared NSURLCache instance.
Discussion
Applications that do not have special caching requirements or constraints should find the default shared cache instance acceptable. An application with more specific needs can create a custom NSURLCache object and set it as the shared cache instance using setSharedURLCache:. The application should do so before any calls to this method.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hInstance Methods
cachedResponseForRequest:
Returns the cached URL response in the cache for the specified URL request.
Parameters
- request
The URL request whose cached response is desired.
Return Value
The cached URL response for request, or nil if no response has been cached.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hcurrentDiskUsage
Returns the current size of the receiver’s on-disk cache, in bytes.
Return Value
The current size of the receiver’s on-disk cache, in bytes.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hcurrentMemoryUsage
Returns the current size of the receiver’s in-memory cache, in bytes.
Return Value
The current size of the receiver’s in-memory cache, in bytes.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hdiskCapacity
Returns the capacity of the receiver’s on-disk cache, in bytes.
Return Value
The capacity of the receiver’s on-disk cache, in bytes.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hinitWithMemoryCapacity:diskCapacity:diskPath:
Initializes an NSURLCache object with the specified values.
Parameters
- memoryCapacity
The memory capacity of the cache, in bytes.
- diskCapacity
The disk capacity of the cache, in bytes.
- path
In OS X, path is the location at which to store the on-disk cache.
In iOS, path is the name of a subdirectory of the application’s default cache directory in which to store the on-disk cache (the subdirectory is created if it does not exist).
Return Value
The initialized NSURLCache object.
Discussion
The returned NSURLCache is backed by disk, so developers can be more liberal with space when choosing the capacity for this kind of cache. A disk cache measured in the tens of megabytes should be acceptable in most cases.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hmemoryCapacity
Returns the capacity of the receiver’s in-memory cache, in bytes.
Return Value
The capacity of the receiver’s in-memory cache, in bytes.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hremoveAllCachedResponses
Clears the receiver’s cache, removing all stored cached URL responses.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hremoveCachedResponseForRequest:
Removes the cached URL response for a specified URL request.
Parameters
- request
The URL request whose cached URL response should be removed. If there is no corresponding cached URL response, no action is taken.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hsetDiskCapacity:
Sets the receiver’s on-disk cache capacity
Parameters
- diskCapacity
The new on-disk cache capacity, in bytes. The on-disk cache will truncate its contents to diskCapacity, if necessary.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hsetMemoryCapacity:
Sets the receiver’s in-memory cache capacity.
Parameters
- memoryCapacity
The new in-memory cache capacity, in bytes. The in-memory cache will truncate its contents to memoryCapacity, if necessary.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.hstoreCachedResponse:forRequest:
Stores a cached URL response for a specified request
Parameters
- cachedResponse
The cached URL response to store.
- request
The request for which the cached URL response is being stored.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSURLCache.h© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-05-11)