Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

LRU Caching on Disk #343

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

muneebali
Copy link

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!

@micahnyc
Copy link

hey, is this making it into master? I'm interested...

@muneebali
Copy link
Author

Fingers crossed.

@MugunthKumar
Copy link
Owner

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//pull/343#issuecomment-18663703
.

Regards,

M.Mugunth Kumar
W: http://mugunthkumar.com
B: http://blog.mugunthkumar.com
Singapore

@vittoriom
Copy link

any news on this?

@muneebali
Copy link
Author

Not yet

@vittoriom
Copy link

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

:)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants