Class: NSURLCache

Inherits:
NSObject show all

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.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (Object) setSharedURLCache(cache)

Sets the shared NSURLCache instance to a specified cache object. 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.

Parameters:

  • cache (NSURLCache)

    The cache object to use as the shared cache object.

Returns:

+ (NSURLCache) sharedURLCache

Returns the shared NSURLCache instance. 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.

Returns:

Instance Method Details

- (NSCachedURLResponse) cachedResponseForRequest(request)

Returns the cached URL response in the cache for the specified URL request.

Parameters:

  • request (NSURLRequest)

    The URL request whose cached response is desired.

Returns:

  • (NSCachedURLResponse)

    The cached URL response for request, or nil if no response has been cached.

- (Integer) currentDiskUsage

Returns the current size of the receiver’s on-disk cache, in bytes.

Returns:

  • (Integer)

    The current size of the receiver’s on-disk cache, in bytes.

- (Integer) currentMemoryUsage

Returns the current size of the receiver’s in-memory cache, in bytes.

Returns:

  • (Integer)

    The current size of the receiver’s in-memory cache, in bytes.

- (Integer) diskCapacity

Returns the capacity of the receiver’s on-disk cache, in bytes.

Returns:

  • (Integer)

    The capacity of the receiver’s on-disk cache, in bytes.

- (Object) initWithMemoryCapacity(memoryCapacity, diskCapacity:diskCapacity, diskPath:path)

Initializes an NSURLCache object with the specified values. 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.

Parameters:

  • memoryCapacity (Integer)

    The memory capacity of the cache, in bytes.

  • diskCapacity (Integer)

    The disk capacity of the cache, in bytes.

  • path (String)

    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).

Returns:

- (Integer) memoryCapacity

Returns the capacity of the receiver’s in-memory cache, in bytes.

Returns:

  • (Integer)

    The capacity of the receiver’s in-memory cache, in bytes.

- (Object) removeAllCachedResponses

Clears the receiver’s cache, removing all stored cached URL responses.

Returns:

- (Object) removeCachedResponseForRequest(request)

Removes the cached URL response for a specified URL request.

Parameters:

  • request (NSURLRequest)

    The URL request whose cached URL response should be removed. If there is no corresponding cached URL response, no action is taken.

Returns:

- (Object) setDiskCapacity(diskCapacity)

Sets the receiver’s on-disk cache capacity

Parameters:

  • diskCapacity (Integer)

    The new on-disk cache capacity, in bytes. The on-disk cache will truncate its contents to diskCapacity, if necessary.

Returns:

- (Object) setMemoryCapacity(memoryCapacity)

Sets the receiver’s in-memory cache capacity.

Parameters:

  • memoryCapacity (Integer)

    The new in-memory cache capacity, in bytes. The in-memory cache will truncate its contents to memoryCapacity, if necessary.

Returns:

- (Object) storeCachedResponse(cachedResponse, forRequest:request)

Stores a cached URL response for a specified request

Parameters:

  • cachedResponse (NSCachedURLResponse)

    The cached URL response to store.

  • request (NSURLRequest)

    The request for which the cached URL response is being stored.

Returns: