Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.2 with Safari 1.0 installed. Available in Mac OS X v10.2.7 and later. |
Companion guide | |
Declared in | NSURLCache.h |
Related sample code |
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.
Sets the shared NSURLCache instance to a specified cache object.
+ (void)setSharedURLCache:(NSURLCache *)cache
The cache object to use as the shared cache object.
Applications that have special caching requirements or constraints should use this method to specify an NSURLCache instance with customized cache settings.
NSURLCache.h
Returns the shared NSURLCache instance.
+ (NSURLCache *)sharedURLCache
The shared NSURLCache instance.
The disk path is set to: <user_home_directory>/Library/Caches/<current_process_name>
. The user’s home directory is determined by calling NSHomeDirectory
and the current process name is determined using [[NSProcessInfo processInfo] processName]
.
Applications that do not have special caching requirements or constraints should find the default shared cache instance acceptable. Applications with more specific needs can create a custom NSURLCache
object and set it as the shared cache instance using setSharedURLCache:
.
NSURLCache.h
Returns the cached URL response in the cache for the specified URL request.
- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request
The URL request whose cached response is desired.
The cached URL response for request, or nil
if no response has been cached.
NSURLCache.h
Returns the current size of the receiver’s on-disk cache, in bytes.
- (NSUInteger)currentDiskUsage
The current size of the receiver’s on-disk cache, in bytes.
NSURLCache.h
Returns the current size of the receiver’s in-memory cache, in bytes.
- (NSUInteger)currentMemoryUsage
The current size of the receiver’s in-memory cache, in bytes.
NSURLCache.h
Returns the capacity of the receiver’s on-disk cache, in bytes.
- (NSUInteger)diskCapacity
The capacity of the receiver’s on-disk cache, in bytes.
NSURLCache.h
Initializes an NSURLCache object with the specified values.
- (id)initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity diskPath:(NSString *)path
The memory capacity of the cache, in bytes.
The disk capacity of the cache, in bytes.
The location at which to store the on-disk cache.
The initialized NSURLCache object.
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.
NSURLCache.h
Returns the capacity of the receiver’s in-memory cache, in bytes.
- (NSUInteger)memoryCapacity
The capacity of the receiver’s in-memory cache, in bytes.
NSURLCache.h
Clears the receiver’s cache, removing all stored cached URL responses.
- (void)removeAllCachedResponses
NSURLCache.h
Removes the cached URL response for a specified URL request.
- (void)removeCachedResponseForRequest:(NSURLRequest *)request
The URL request whose cached URL response should be removed. If there is no corresponding cached URL response, no action is taken.
NSURLCache.h
Sets the receiver’s on-disk cache capacity
- (void)setDiskCapacity:(NSUInteger)diskCapacity
The new on-disk cache capacity, in bytes. The on-disk cache will truncate its contents to diskCapacity, if necessary.
NSURLCache.h
Sets the receiver’s in-memory cache capacity.
- (void)setMemoryCapacity:(NSUInteger)memoryCapacity
The new in-memory cache capacity, in bytes. The in-memory cache will truncate its contents to memoryCapacity, if necessary.
NSURLCache.h
Stores a cached URL response for a specified request
- (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NSURLRequest *)request
The cached URL response to store.
The request for which the cached URL response is being stored.
NSURLCache.h
© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-03-11)