TTURLCache Class Reference
A general purpose URL cache for caching data in memory and on disk. More...
#import <TTURLCache.h>
Public Member Functions | |
| (id) | - initWithName: |
| (NSString *) | - keyForURL: |
| Gets the key that would be used to cache a URL response. | |
| (NSString *) | - cachePathForURL: |
| Gets the path in the cache where a URL may be stored. | |
| (NSString *) | - cachePathForKey: |
| Gets the path in the cache where a key may be stored. | |
| (NSString *) | - etagCachePathForKey: |
| Etag cache files are stored in the following way: File name: <key> File data: <etag value>=""> | |
| (BOOL) | - hasDataForURL: |
| Determines if there is a cache entry for a URL. | |
| (BOOL) | - hasDataForKey:expires: |
| Determines if there is a cache entry for a key. | |
| (BOOL) | - hasImageForURL:fromDisk: |
| Determines if there is an image cache entry for a URL. | |
| (NSData *) | - dataForURL: |
| Gets the data for a URL from the cache if it exists. | |
| (NSData *) | - dataForURL:expires:timestamp: |
| Gets the data for a URL from the cache if it exists and is newer than a minimum timestamp. | |
| (NSData *) | - dataForKey:expires:timestamp: |
| (id) | - imageForURL: |
| Gets an image from the in-memory image cache. | |
| (id) | - imageForURL:fromDisk: |
| (NSString *) | - etagForKey: |
| Get an etag value for a given cache key. | |
| (void) | - storeData:forURL: |
| Stores a data on disk. | |
| (void) | - storeData:forKey: |
| (void) | - storeImage:forURL: |
| Stores an image in the memory cache. | |
| (void) | - storeEtag:forKey: |
| Stores an etag value in the etag cache. | |
| (NSString *) | - storeTemporaryImage:toDisk: |
| Convenient way to create a temporary URL for some data and cache it in memory. | |
| (NSString *) | - storeTemporaryData: |
| Convenient way to create a temporary URL for some data and cache in on disk. | |
| (NSString *) | - storeTemporaryFile: |
| Convenient way to create a temporary URL for a file and move it to the disk cache. | |
| (void) | - moveDataForURL:toURL: |
| Moves the data currently stored under one URL to another URL. | |
| (void) | - moveDataFromPath:toURL: |
| (NSString *) | - moveDataFromPathToTemporaryURL: |
| (void) | - removeURL:fromDisk: |
| Removes the data for a URL from the memory cache and optionally from the disk cache. | |
| (void) | - removeKey: |
| (void) | - removeAll: |
| Erases the memory cache and optionally the disk cache. | |
| (void) | - invalidateURL: |
| Invalidates the file in the disk cache so that its modified timestamp is the current time minus the default cache expiration age. | |
| (void) | - invalidateKey: |
| (void) | - invalidateAll |
| Invalidates all files in the disk cache according to rules explained in `invalidateURL`. | |
| (void) | - logMemoryUsage |
Static Public Member Functions | |
| (TTURLCache *) | + cacheWithName: |
| Gets a shared cache identified with a unique name. | |
| (TTURLCache *) | + sharedCache |
| Gets the shared cache singleton used across the application. | |
| (void) | + setSharedCache: |
| Sets the shared cache singleton used across the application. | |
| (NSString *) | + cachePathWithName: |
| Creates paths as necessary and returns the cache path for the given name. | |
| (NSString *) | + doubleImageURLPath: |
| Reveal these private methods for testing. | |
Protected Attributes | |
| NSString * | _name |
| NSString * | _cachePath |
| NSMutableDictionary * | _imageCache |
| NSMutableArray * | _imageSortedList |
| NSUInteger | _totalPixelCount |
| NSUInteger | _maxPixelCount |
| NSInteger | _totalLoading |
| NSTimeInterval | _invalidationAge |
| BOOL | _disableDiskCache |
| BOOL | _disableImageCache |
Properties | |
| BOOL | disableDiskCache |
| Disables the disk cache. | |
| BOOL | disableImageCache |
| Disables the in-memory cache for images. | |
| NSString * | cachePath |
| Gets the path to the directory of the disk cache. | |
| NSString * | etagCachePath |
| Gets the path to the directory of the disk cache for etags. | |
| NSUInteger | maxPixelCount |
| The maximum number of pixels to keep in memory for cached images. | |
| NSTimeInterval | invalidationAge |
| The amount of time to set back the modification timestamp on files when invalidating them. | |
Detailed Description
A general purpose URL cache for caching data in memory and on disk.
Etags are supported.
Member Function Documentation
Gets the data for a URL from the cache if it exists.
- Returns:
- nil if the URL is not cached.
| - (NSData *) dataForURL: | (NSString*) | URL | ||
| expires: | (NSTimeInterval) | expirationAge | ||
| timestamp: | (NSDate**) | timestamp | ||
Gets the data for a URL from the cache if it exists and is newer than a minimum timestamp.
- Returns:
- nil if hthe URL is not cached or if the cache entry is older than the minimum.
Etag cache files are stored in the following way: File name: <key> File data: <etag value>="">
- Returns:
- The etag cache path for the given key.
| - (id) imageForURL: | (NSString*) | URL |
Gets an image from the in-memory image cache.
- Returns:
- nil if the URL is not cached.
| - (void) invalidateURL: | (NSString*) | URL |
Invalidates the file in the disk cache so that its modified timestamp is the current time minus the default cache expiration age.
This ensures that the next time the URL is requested from the cache it will be loaded from the network if the default cache expiration age is used.
Moves the data currently stored under one URL to another URL.
This is handy when you are caching data at a temporary URL while the permanent URL is being retrieved from a server. Once you know the permanent URL you can use this to move the data.
Convenient way to create a temporary URL for some data and cache in on disk.
- Returns:
- The temporary URL
| - (NSString *) storeTemporaryFile: | (NSURL*) | fileURL |
Convenient way to create a temporary URL for a file and move it to the disk cache.
- Returns:
- The temporary URL
Convenient way to create a temporary URL for some data and cache it in memory.
- Returns:
- The temporary URL
Property Documentation
- (BOOL) disableDiskCache [read, write, assign] |
Disables the disk cache.
Disables etag support as well.
- (NSUInteger) maxPixelCount [read, write, assign] |
The maximum number of pixels to keep in memory for cached images.
Setting this to zero will allow an unlimited number of images to be cached. The default is zero.
The documentation for this class was generated from the following files:
- Three20Network/Headers/TTURLCache.h
- Three20Network/Sources/TTURLCache.m
