Merge pull request #115 from jcole/master

Added a few methods to SDImageCache to get number of items in file cache and memory cache, and size of items in memory
This commit is contained in:
Olivier Poitrey 2012-05-11 12:47:04 -07:00
commit af3924c447
2 changed files with 45 additions and 0 deletions

View File

@ -122,4 +122,19 @@
*/
- (int)getSize;
/**
* Get the number of images in the disk cache
*/
- (int)getDiskCount;
/**
* Get the total size of images in memory cache
*/
- (int)getMemorySize;
/**
* Get the number of images in the memory cache
*/
- (int)getMemoryCount;
@end

View File

@ -360,4 +360,34 @@ static SDImageCache *instance;
return size;
}
- (int)getDiskCount
{
int count = 0;
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:diskCachePath];
for (NSString *fileName in fileEnumerator)
{
count += 1;
}
return count;
}
- (int)getMemorySize
{
int size = 0;
for(id key in [memCache allKeys])
{
UIImage *img = [memCache valueForKey:key];
size += [UIImageJPEGRepresentation(img, 0) length];
};
return size;
}
- (int)getMemoryCount
{
return [[memCache allKeys] count];
}
@end