Skip to content
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
MKSG-MugunthKumar:masterfrom
muneebali:master
Open

LRU Caching on Disk#343
muneebali wants to merge 2 commits into
MKSG-MugunthKumar:masterfrom
muneebali:master

Conversation

@muneebali

Copy link
Copy Markdown

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
Copy Markdown

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

@muneebali

Copy link
Copy Markdown
Author

Fingers crossed.

@MKSG-MugunthKumar

Copy link
Copy Markdown
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
Copy Markdown

any news on this?

@muneebali

Copy link
Copy Markdown
Author

Not yet

@vittoriom

Copy link
Copy Markdown

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