SDImageCache Class Reference
| Inherits from | NSObject |
| Declared in | SDImageCache.h SDImageCache.m |
Overview
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.
Tasks
-
maxMemoryCostproperty -
maxCacheAgeproperty -
maxCacheSizeproperty -
+ sharedImageCache -
– initWithNamespace: -
– addReadOnlyCachePath: -
– storeImage:forKey: -
– storeImage:forKey:toDisk: -
– storeImage:recalculateFromImage:imageData:forKey:toDisk: -
– queryDiskCacheForKey:done: -
– imageFromMemoryCacheForKey: -
– imageFromDiskCacheForKey: -
– removeImageForKey: -
– removeImageForKey:fromDisk: -
– clearMemory -
– clearDisk -
– cleanDisk -
– getSize -
– getDiskCount -
– calculateSizeWithCompletionBlock: -
– diskImageExistsWithKey:
Properties
maxCacheAge
The maximum length of time to keep an image in the cache, in seconds
@property (assign, nonatomic) NSInteger maxCacheAgeDeclared In
SDImageCache.hInstance Methods
addReadOnlyCachePath:
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
- (void)addReadOnlyCachePath:(NSString *)pathParameters
- path
The path to use for this read-only cache path
Declared In
SDImageCache.hcalculateSizeWithCompletionBlock:
Asynchronously calculate the disk cache’s size.
- (void)calculateSizeWithCompletionBlock:(void ( ^ ) ( NSUInteger fileCount , unsigned long long totalSize ))completionBlockDeclared In
SDImageCache.hdiskImageExistsWithKey:
Check if image exists in cache already
- (BOOL)diskImageExistsWithKey:(NSString *)keyDeclared In
SDImageCache.hgetDiskCount
Get the number of images in the disk cache
- (int)getDiskCountDeclared In
SDImageCache.hgetSize
Get the size used by the disk cache
- (unsigned long long)getSizeDeclared In
SDImageCache.himageFromDiskCacheForKey:
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
SDImageCache.himageFromMemoryCacheForKey:
Query the memory cache synchronously.
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)keyParameters
- key
The unique key used to store the wanted image
Declared In
SDImageCache.hinitWithNamespace:
Init a new cache store with a specific namespace
- (id)initWithNamespace:(NSString *)nsParameters
- ns
The namespace to use for this cache store
Declared In
SDImageCache.hqueryDiskCacheForKey:done:
Query the disk cache asynchronously.
- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(void ( ^ ) ( UIImage *image , SDImageCacheType cacheType ))doneBlockParameters
- key
The unique key used to store the wanted image
Declared In
SDImageCache.hremoveImageForKey:
Remove the image from memory and disk cache synchronously
- (void)removeImageForKey:(NSString *)keyParameters
- key
The unique image cache key
Declared In
SDImageCache.hremoveImageForKey:fromDisk:
Remove the image from memory and optionaly 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
SDImageCache.hstoreImage: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
SDImageCache.hstoreImage: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
SDImageCache.hstoreImage: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
SDImageCache.h