TuSDKNetworkImageCache Class Reference
| Inherits from | NSObject |
|---|---|
| Declared in | TuSDKNetworkImageCache.h |
Overview
TuSDKNetworkImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed asynchronous so it doesn’t add unnecessary latency to the UI.
maxMemoryCost
The maximum “total cost” of the in-memory image cache. The cost function is the number of pixels held in memory.
@property (assign, nonatomic) NSUInteger maxMemoryCostDeclared In
TuSDKNetworkImageCache.h
maxCacheAge
The maximum length of time to keep an image in the cache, in seconds
@property (assign, nonatomic) NSInteger maxCacheAgeDeclared In
TuSDKNetworkImageCache.h
maxCacheSize
The maximum size of the cache, in bytes.
@property (assign, nonatomic) NSUInteger maxCacheSizeDeclared In
TuSDKNetworkImageCache.h
+ sharedImageCache
Returns global shared cache instance
+ (TuSDKNetworkImageCache *)sharedImageCacheReturn Value
TuSDKNetworkImageCache global instance
Declared In
TuSDKNetworkImageCache.h
– initWithNamespace:
Init a new cache store with a specific namespace
- (id)initWithNamespace:(NSString *)nsParameters
ns |
The namespace to use for this cache store |
|---|
Declared In
TuSDKNetworkImageCache.h
– addReadOnlyCachePath:
Add a read-only cache path to search for images pre-cached by TuSDKNetworkImageCache Useful if you want to bundle pre-loaded images with your app
- (void)addReadOnlyCachePath:(NSString *)pathParameters
path |
The path to use for this read-only cache path |
|---|
Declared In
TuSDKNetworkImageCache.h
– storeImage:forKey:
Store an image into memory and disk cache at the given key.
- (void)storeImage:(UIImage *)image forKey:(NSString *)keyParameters
image |
The image to store |
|---|---|
key |
The unique image cache key, usually it’s image absolute URL |
Declared In
TuSDKNetworkImageCache.h
– storeImage:forKey:toDisk:
Store an image into memory and optionally disk cache at the given key.
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDiskParameters
image |
The image to store |
|---|---|
key |
The unique image cache key, usually it’s image absolute URL |
toDisk |
Store the image to disk cache if YES |
Declared In
TuSDKNetworkImageCache.h
– storeImage:recalculateFromImage:imageData:forKey:toDisk:
Store an image into memory and optionally disk cache at the given key.
- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDiskParameters
image |
The image to store |
|---|---|
recalculate |
BOOL indicates if imageData can be used or a new data should be constructed from the UIImage |
imageData |
The image data as returned by the server, this representation will be used for disk storage instead of converting the given image object into a storable/compressed image format in order to save quality and CPU |
key |
The unique image cache key, usually it’s image absolute URL |
toDisk |
Store the image to disk cache if YES |
Declared In
TuSDKNetworkImageCache.h
– queryDiskCacheForKey:done:
Query the disk cache asynchronously.
- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(TuSDKWebImageQueryCompletedBlock)doneBlockParameters
key |
The unique key used to store the wanted image |
|---|
Declared In
TuSDKNetworkImageCache.h
– imageFromMemoryCacheForKey:
Query the memory cache synchronously.
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)keyParameters
key |
The unique key used to store the wanted image |
|---|
Declared In
TuSDKNetworkImageCache.h
– imageFromDiskCacheForKey:
Query the disk cache synchronously after checking the memory cache.
- (UIImage *)imageFromDiskCacheForKey:(NSString *)keyParameters
key |
The unique key used to store the wanted image |
|---|
Declared In
TuSDKNetworkImageCache.h
– removeImageForKey:
Remove the image from memory and disk cache synchronously
- (void)removeImageForKey:(NSString *)keyParameters
key |
The unique image cache key |
|---|
Declared In
TuSDKNetworkImageCache.h
– removeImageForKey:withCompletion:
Remove the image from memory and disk cache synchronously
- (void)removeImageForKey:(NSString *)key withCompletion:(TuSDKWebImageNoParamsBlock)completionParameters
key |
The unique image cache key |
|---|---|
completion |
An block that should be executed after the image has been removed (optional) |
Declared In
TuSDKNetworkImageCache.h
– removeImageForKey:fromDisk:
Remove the image from memory and optionally disk cache synchronously
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDiskParameters
key |
The unique image cache key |
|---|---|
fromDisk |
Also remove cache entry from disk if YES |
Declared In
TuSDKNetworkImageCache.h
– removeImageForKey:fromDisk:withCompletion:
Remove the image from memory and optionally disk cache synchronously
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(TuSDKWebImageNoParamsBlock)completionParameters
key |
The unique image cache key |
|---|---|
fromDisk |
Also remove cache entry from disk if YES |
completion |
An block that should be executed after the image has been removed (optional) |
Declared In
TuSDKNetworkImageCache.h
– clearMemory
Clear all memory cached images
- (void)clearMemoryDeclared In
TuSDKNetworkImageCache.h
– clearDiskOnCompletion:
Clear all disk cached images. Non-blocking method - returns immediately.
- (void)clearDiskOnCompletion:(TuSDKWebImageNoParamsBlock)completionParameters
completion |
An block that should be executed after cache expiration completes (optional) |
|---|
Declared In
TuSDKNetworkImageCache.h
– clearDisk
Clear all disk cached images
- (void)clearDiskSee Also
Declared In
TuSDKNetworkImageCache.h
– cleanDiskWithCompletionBlock:
Remove all expired cached image from disk. Non-blocking method - returns immediately.
- (void)cleanDiskWithCompletionBlock:(TuSDKWebImageNoParamsBlock)completionBlockParameters
completionBlock |
An block that should be executed after cache expiration completes (optional) |
|---|
Declared In
TuSDKNetworkImageCache.h
– cleanDisk
Remove all expired cached image from disk
- (void)cleanDiskSee Also
Declared In
TuSDKNetworkImageCache.h
– lsqGetSize
Get the size used by the disk cache
- (NSUInteger)lsqGetSizeDeclared In
TuSDKNetworkImageCache.h
– getDiskCount
Get the number of images in the disk cache
- (NSUInteger)getDiskCountDeclared In
TuSDKNetworkImageCache.h
– calculateSizeWithCompletionBlock:
Asynchronously calculate the disk cache’s size.
- (void)calculateSizeWithCompletionBlock:(TuSDKWebImageCalculateSizeBlock)completionBlockDeclared In
TuSDKNetworkImageCache.h
– diskImageExistsWithKey:completion:
Async check if image exists in disk cache already (does not load the image)
- (void)diskImageExistsWithKey:(NSString *)key completion:(TuSDKWebImageCheckCacheCompletionBlock)completionBlockParameters
key |
the key describing the url |
|---|---|
completionBlock |
the block to be executed when the check is done. |
Discussion
Note: the completion block will be always executed on the main queue
Declared In
TuSDKNetworkImageCache.h
– diskImageExistsWithKey:
Check if image exists in disk cache already (does not load the image)
- (BOOL)diskImageExistsWithKey:(NSString *)keyParameters
key |
the key describing the url |
|---|
Return Value
YES if an image exists for the given key
Declared In
TuSDKNetworkImageCache.h
– cachePathForKey:inPath:
Get the cache path for a certain key (needs the cache path root folder)
- (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)pathParameters
key |
the key (can be obtained from url using cacheKeyForURL) |
|---|---|
path |
the cach path root folder |
Return Value
the cache path
Declared In
TuSDKNetworkImageCache.h
– defaultCachePathForKey:
Get the default cache path for a certain key
- (NSString *)defaultCachePathForKey:(NSString *)keyParameters
key |
the key (can be obtained from url using cacheKeyForURL) |
|---|
Return Value
the default cache path
Declared In
TuSDKNetworkImageCache.h