MKNetworkKit
MKNetworkKit copied to clipboard
LRU Caching on Disk
I have implemented LRU caching on disk. Now in emptyCache method, it doesn't remove all the cache and instead removes the cache unless we are in limit set in cacheDiskSize. Also an observer to UIApplicationDidBecomeActiveNotification is added in useCache method so that it removes excess cache whenever app becomes active.
Please review if it works for you. Thanks!
hey, is this making it into master? I'm interested...
Fingers crossed.
I'm interested in this. Haven't gotten time to go through and merge the code. Give me some time.
On Thursday, May 30, 2013, muneebali wrote:
Fingers crossed.
— Reply to this email directly or view it on GitHubhttps://github.com/MugunthKumar/MKNetworkKit/pull/343#issuecomment-18663703 .
Regards,
M.Mugunth Kumar W: http://mugunthkumar.com B: http://blog.mugunthkumar.com Singapore
any news on this?
Not yet
Ok, I investigated and there are no assumptions to be made on the cache directory, so I'm not sure your emptyCache implementation is a LRU one. To do that, you should do something like
NSArray *directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[NSURL fileURLWithPath:[self cacheDirectoryName]]
includingPropertiesForKeys:@[NSURLContentModificationDateKey]
options:NSDirectoryEnumerationSkipsHiddenFiles
error:&error];
NSArray *sortedContent = [directoryContents sortedArrayUsingComparator:
^(NSURL *file1, NSURL *file2)
{
// compare
NSDate *file1Date;
[file1 getResourceValue:&file1Date forKey:NSURLContentModificationDateKey error:nil];
NSDate *file2Date;
[file2 getResourceValue:&file2Date forKey:NSURLContentModificationDateKey error:nil];
// Ascending:
return [file1Date compare: file2Date];
// Descending:
//return [file2Date compare: file1Date];
}];
And of course iterate on sortedContent instead of directoryContents
:)