TKImageCache Class Reference
Inherits from | NSCache |
Declared in | TKImageCache.h |
Overview
An TKImageCache
object provides a way to manage images between the network, disk and NSCache
.
Tasks
Initializing An Image Cache Object
-
– init
Initialize a new image cache object.
-
– initWithCacheDirectoryName:
Initialize a new image cache object.
Properties
-
shouldNetworkActivity
Shows network activity monitor in status bar when network requests are created.
property -
imagesQueue
The queue that manages all network requests for images
property -
cacheDirectoryName
The directory where images are stored on disk
property -
notificationName
The notification name posted to
propertyNSNotificationCenter
-
timeTillRefreshCache
The threshold of time images on disk need to be created before to be read from disk. Otherwise the images will be requested from the network again. The time needs to be greater than zero to for the creation date to be check. Default is -1.
property
Getting an image
-
– imageForKey:url:queueIfNeeded:
Returns an image if cached or properly routes requests to grab the image from disk or network.
-
– imageForKey:url:queueIfNeeded:tag:
Returns an image if cached or properly routes requests to grab the image from disk or network.
-
– cachedImageForKey:
Grabs an image object directly from disk.
-
– imageExistsWithKey:
Checks to see if an image exists in cache or on disk for the given key.
Managing images and requests.
-
– cancelOperations
Cancel all image requests
-
– removeRequestForKey:
Remove an image request for a specific key
-
– clearCachedImages
Clears local cache and remove all images from disk
-
– removeCachedImagesFromDiskOlderThanTime:
Remove all images from disk that we’re create earlier than a certain time
For subclassing
-
– cacheDirectoryPath
The directory where images are stored on disk.
-
– adjustImageRecieved:
Perform image adjustments before storing it in local cache.
Properties
cacheDirectoryName
The directory where images are stored on disk
@property (nonatomic, copy) NSString *cacheDirectoryName
Discussion
The directory where images are stored on disk
Declared In
TKImageCache.h
imagesQueue
The queue that manages all network requests for images
@property (nonatomic, strong) TKNetworkQueue *imagesQueue
Discussion
The queue that manages all network requests for images
Declared In
TKImageCache.h
notificationName
The notification name posted to NSNotificationCenter
@property (nonatomic, copy) NSString *notificationName
Discussion
The notification name posted to NSNotificationCenter
Declared In
TKImageCache.h
shouldNetworkActivity
Shows network activity monitor in status bar when network requests are created.
@property BOOL shouldNetworkActivity
Discussion
Shows network activity monitor in status bar when network requests are created.
Declared In
TKImageCache.h
timeTillRefreshCache
The threshold of time images on disk need to be created before to be read from disk. Otherwise the images will be requested from the network again. The time needs to be greater than zero to for the creation date to be check. Default is -1.
@property (nonatomic, assign) NSTimeInterval timeTillRefreshCache
Discussion
The threshold of time images on disk need to be created before to be read from disk. Otherwise the images will be requested from the network again. The time needs to be greater than zero to for the creation date to be check. Default is -1.
Declared In
TKImageCache.h
Instance Methods
adjustImageRecieved:
Perform image adjustments before storing it in local cache.
- (UIImage *)adjustImageRecieved:(UIImage *)image
Parameters
- image
The image received from disk or the network.
Return Value
The adjusted image.
Discussion
Perform image adjustments before storing it in local cache.
Declared In
TKImageCache.h
cacheDirectoryPath
The directory where images are stored on disk.
- (NSString *)cacheDirectoryPath
Return Value
A NSString
with the location to store images.
Discussion
The directory where images are stored on disk.
Declared In
TKImageCache.h
cachedImageForKey:
Grabs an image object directly from disk.
- (UIImage *)cachedImageForKey:(NSString *)key
Parameters
- key
The key corresponding to a specific image..
Return Value
Returns an unadjusted UIImage
object direct from disk.
Discussion
Grabs an image object directly from disk.
Declared In
TKImageCache.h
cancelOperations
Cancel all image requests
- (void)cancelOperations
Discussion
Cancel all image requests
Declared In
TKImageCache.h
clearCachedImages
Clears local cache and remove all images from disk
- (void)clearCachedImages
Discussion
Clears local cache and remove all images from disk
Declared In
TKImageCache.h
imageExistsWithKey:
Checks to see if an image exists in cache or on disk for the given key.
- (BOOL)imageExistsWithKey:(NSString *)key
Parameters
- key
The key corresponding to a specific image.
Return Value
Returns YES is the image corresponding to the key exists on disk or in NSCache, otherwise NO.
Discussion
Checks to see if an image exists in cache or on disk for the given key.
Declared In
TKImageCache.h
imageForKey:url:queueIfNeeded:
Returns an image if cached or properly routes requests to grab the image from disk or network.
- (UIImage *)imageForKey:(NSString *)key url:(NSURL *)url queueIfNeeded:(BOOL)queueIfNeeded
Parameters
- key
The key corresponding to a specific image.
- url
The URL to grab the image data from the network.
- queueIfNeeded
If the image is not on disk or in cache, a network request will be create to grab the image data.
Return Value
Returns an UIImage
object if the image is in NSCache
.
Discussion
Returns an image if cached or properly routes requests to grab the image from disk or network.
Declared In
TKImageCache.h
imageForKey:url:queueIfNeeded:tag:
Returns an image if cached or properly routes requests to grab the image from disk or network.
- (UIImage *)imageForKey:(NSString *)key url:(NSURL *)url queueIfNeeded:(BOOL)queueIfNeeded tag:(NSUInteger)tag
Parameters
- key
The key corresponding to a specific image.
- url
The URL to grab the image data from the network.
- queueIfNeeded
If the image is not on disk or in cache, a network request will be create to grab the image data.
- tag
A tag to associate the image with the rest of your application.
Return Value
Returns an UIImage
object if the image is in NSCache
.
Discussion
Returns an image if cached or properly routes requests to grab the image from disk or network.
Declared In
TKImageCache.h
init
Initialize a new image cache object.
- (id)init
Return Value
A new created TKImageCache
object.
Discussion
Initialize a new image cache object.
Declared In
TKImageCache.h
initWithCacheDirectoryName:
Initialize a new image cache object.
- (id)initWithCacheDirectoryName:(NSString *)cacheDirectoryName
Parameters
- cacheDirectoryName
The name of the folder to place cached images to disk.
Return Value
A new created TKImageCache
object.
Discussion
Initialize a new image cache object.
Declared In
TKImageCache.h
removeCachedImagesFromDiskOlderThanTime:
Remove all images from disk that we’re create earlier than a certain time
- (void)removeCachedImagesFromDiskOlderThanTime:(NSTimeInterval)time
Parameters
- time
The time for which all images files must be created before to remain on disk.
Discussion
Remove all images from disk that we’re create earlier than a certain time
Declared In
TKImageCache.h