LuxChat  2.0
Instant messenger for iOS
Instance Methods | Class Methods | Properties | List of all members
SDImageCache Class Reference

#import <SDImageCache.h>

Inheritance diagram for SDImageCache:

Instance Methods

(id) - initWithNamespace:
 
(NSString *) - makeDiskCachePath:
 
(void) - addReadOnlyCachePath:
 
(void) - storeImage:forKey:
 
(void) - storeImage:forKey:toDisk:
 
(void) - storeImage:recalculateFromImage:imageData:forKey:toDisk:
 
(NSOperation *) - queryDiskCacheForKey:done:
 
(UIImage *) - imageFromMemoryCacheForKey:
 
(UIImage *) - imageFromDiskCacheForKey:
 
(void) - removeImageForKey:
 
(void) - removeImageForKey:withCompletion:
 
(void) - removeImageForKey:fromDisk:
 
(void) - removeImageForKey:fromDisk:withCompletion:
 
(void) - clearMemory
 
(void) - clearDiskOnCompletion:
 
(void) - clearDisk
 
(void) - cleanDiskWithCompletionBlock:
 
(void) - cleanDisk
 
(NSUInteger) - getSize
 
(NSUInteger) - getDiskCount
 
(void) - calculateSizeWithCompletionBlock:
 
(void) - diskImageExistsWithKey:completion:
 
(BOOL) - diskImageExistsWithKey:
 
(NSString *) - cachePathForKey:inPath:
 
(NSString *) - defaultCachePathForKey:
 

Class Methods

(SDImageCache *) + sharedImageCache
 

Properties

BOOL shouldDecompressImages
 
NSUInteger maxMemoryCost
 
NSUInteger maxMemoryCountLimit
 
NSInteger maxCacheAge
 
NSUInteger maxCacheSize
 

Detailed Description

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

Method Documentation

- (void) addReadOnlyCachePath: (NSString *)  path

Add a read-only cache path to search for images pre-cached by SDImageCache Useful if you want to bundle pre-loaded images with your app

Parameters
pathThe path to use for this read-only cache path
- (NSString *) cachePathForKey: (NSString *)  key
inPath: (NSString *)  path 

Get the cache path for a certain key (needs the cache path root folder)

Parameters
keythe key (can be obtained from url using cacheKeyForURL)
paththe cach path root folder
Returns
the cache path
- (void) calculateSizeWithCompletionBlock: (SDWebImageCalculateSizeBlock)  completionBlock

Asynchronously calculate the disk cache's size.

- (void) cleanDisk

Remove all expired cached image from disk

See also
- cleanDiskWithCompletionBlock:
- (void) cleanDiskWithCompletionBlock: (SDWebImageNoParamsBlock)  completionBlock

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

Parameters
completionBlockAn block that should be executed after cache expiration completes (optional)
- (void) clearDisk

Clear all disk cached images

See also
- clearDiskOnCompletion:
- (void) clearDiskOnCompletion: (SDWebImageNoParamsBlock)  completion

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

Parameters
completionAn block that should be executed after cache expiration completes (optional)
- (void) clearMemory

Clear all memory cached images

- (NSString *) defaultCachePathForKey: (NSString *)  key

Get the default cache path for a certain key

Parameters
keythe key (can be obtained from url using cacheKeyForURL)
Returns
the default cache path
- (BOOL) diskImageExistsWithKey: (NSString *)  key

Check if image exists in disk cache already (does not load the image)

Parameters
keythe key describing the url
Returns
YES if an image exists for the given key
- (void) diskImageExistsWithKey: (NSString *)  key
completion: (SDWebImageCheckCacheCompletionBlock)  completionBlock 

Async check if image exists in disk cache already (does not load the image)

Parameters
keythe key describing the url
completionBlockthe block to be executed when the check is done.
Note
the completion block will be always executed on the main queue
- (NSUInteger) getDiskCount

Get the number of images in the disk cache

- (NSUInteger) getSize

Get the size used by the disk cache

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

Query the disk cache synchronously after checking the memory cache.

Parameters
keyThe unique key used to store the wanted image
- (UIImage *) imageFromMemoryCacheForKey: (NSString *)  key

Query the memory cache synchronously.

Parameters
keyThe unique key used to store the wanted image
- (id) initWithNamespace: (NSString *)  ns

Init a new cache store with a specific namespace

Parameters
nsThe namespace to use for this cache store
- (NSOperation *) queryDiskCacheForKey: (NSString *)  key
done: (SDWebImageQueryCompletedBlock)  doneBlock 

Query the disk cache asynchronously.

Parameters
keyThe unique key used to store the wanted image
- (void) removeImageForKey: (NSString *)  key

Remove the image from memory and disk cache synchronously

Parameters
keyThe unique image cache key
- (void) removeImageForKey: (NSString *)  key
fromDisk: (BOOL)  fromDisk 

Remove the image from memory and optionally disk cache asynchronously

Parameters
keyThe unique image cache key
fromDiskAlso remove cache entry from disk if YES
- (void) removeImageForKey: (NSString *)  key
fromDisk: (BOOL)  fromDisk
withCompletion: (SDWebImageNoParamsBlock)  completion 

Remove the image from memory and optionally disk cache asynchronously

Parameters
keyThe unique image cache key
fromDiskAlso remove cache entry from disk if YES
completionAn block that should be executed after the image has been removed (optional)
- (void) removeImageForKey: (NSString *)  key
withCompletion: (SDWebImageNoParamsBlock)  completion 

Remove the image from memory and disk cache asynchronously

Parameters
keyThe unique image cache key
completionAn block that should be executed after the image has been removed (optional)
+ (SDImageCache *) sharedImageCache
Initial value:
{
NSFileManager *_fileManager

Returns global shared cache instance

Returns
SDImageCache global instance
- (void) storeImage: (UIImage *)  image
forKey: (NSString *)  key 

Store an image into memory and disk cache at the given key.

Parameters
imageThe image to store
keyThe unique image cache key, usually it's image absolute URL
- (void) storeImage: (UIImage *)  image
forKey: (NSString *)  key
toDisk: (BOOL)  toDisk 

Store an image into memory and optionally disk cache at the given key.

Parameters
imageThe image to store
keyThe unique image cache key, usually it's image absolute URL
toDiskStore the image to disk cache if YES
- (void) storeImage: (UIImage *)  image
recalculateFromImage: (BOOL)  recalculate
imageData: (NSData *)  imageData
forKey: (NSString *)  key
toDisk: (BOOL)  toDisk 

Store an image into memory and optionally disk cache at the given key.

Parameters
imageThe image to store
recalculateBOOL indicates if imageData can be used or a new data should be constructed from the UIImage
imageDataThe 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
keyThe unique image cache key, usually it's image absolute URL
toDiskStore the image to disk cache if YES

Property Documentation

- (NSInteger) maxCacheAge
readwritenonatomicassign

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

- (NSUInteger) maxCacheSize
readwritenonatomicassign

The maximum size of the cache, in bytes.

- (NSUInteger) maxMemoryCost
readwritenonatomicassign

The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.

- (NSUInteger) maxMemoryCountLimit
readwritenonatomicassign

The maximum number of objects the cache should hold.

- (BOOL) shouldDecompressImages
readwritenonatomicassign

Decompressing images that are downloaded and cached can improve peformance but can consume lot of memory. Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.


The documentation for this class was generated from the following files: