This repository was archived by the owner on Mar 4, 2020. It is now read-only.
LRU Caching on Disk#343
Open
muneebali wants to merge 2 commits into
Open
Conversation
|
hey, is this making it into master? I'm interested... |
Author
|
Fingers crossed. |
Owner
|
I'm interested in this. Haven't gotten time to go through and merge the On Thursday, May 30, 2013, muneebali wrote:
Regards, M.Mugunth Kumar |
|
any news on this? |
Author
|
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 :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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!