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 maxMemoryCost

Declared In

TuSDKNetworkImageCache.h

  maxCacheAge

The maximum length of time to keep an image in the cache, in seconds

@property (assign, nonatomic) NSInteger maxCacheAge

Declared In

TuSDKNetworkImageCache.h

  maxCacheSize

The maximum size of the cache, in bytes.

@property (assign, nonatomic) NSUInteger maxCacheSize

Declared In

TuSDKNetworkImageCache.h

+ sharedImageCache

Returns global shared cache instance

+ (TuSDKNetworkImageCache *)sharedImageCache

Return Value

TuSDKNetworkImageCache global instance

Declared In

TuSDKNetworkImageCache.h

– initWithNamespace:

Init a new cache store with a specific namespace

- (id)initWithNamespace:(NSString *)ns

Parameters

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 *)path

Parameters

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 *)key

Parameters

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

Parameters

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

Parameters

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

Parameters

key

The unique key used to store the wanted image

Declared In

TuSDKNetworkImageCache.h

– imageFromMemoryCacheForKey:

Query the memory cache synchronously.

- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key

Parameters

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 *)key

Parameters

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 *)key

Parameters

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

Parameters

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

Parameters

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

Parameters

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

Declared In

TuSDKNetworkImageCache.h

– clearDiskOnCompletion:

Clear all disk cached images. Non-blocking method - returns immediately.

- (void)clearDiskOnCompletion:(TuSDKWebImageNoParamsBlock)completion

Parameters

completion

An block that should be executed after cache expiration completes (optional)

Declared In

TuSDKNetworkImageCache.h

– clearDisk

Clear all disk cached images

- (void)clearDisk

Declared In

TuSDKNetworkImageCache.h

– cleanDiskWithCompletionBlock:

Remove all expired cached image from disk. Non-blocking method - returns immediately.

- (void)cleanDiskWithCompletionBlock:(TuSDKWebImageNoParamsBlock)completionBlock

Parameters

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

Declared In

TuSDKNetworkImageCache.h

– lsqGetSize

Get the size used by the disk cache

- (NSUInteger)lsqGetSize

Declared In

TuSDKNetworkImageCache.h

– getDiskCount

Get the number of images in the disk cache

- (NSUInteger)getDiskCount

Declared In

TuSDKNetworkImageCache.h

– calculateSizeWithCompletionBlock:

Asynchronously calculate the disk cache’s size.

- (void)calculateSizeWithCompletionBlock:(TuSDKWebImageCalculateSizeBlock)completionBlock

Declared 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)completionBlock

Parameters

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 *)key

Parameters

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 *)path

Parameters

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 *)key

Parameters

key

the key (can be obtained from url using cacheKeyForURL)

Return Value

the default cache path

Declared In

TuSDKNetworkImageCache.h