Skip to content

Commit 63c8d70

Browse files
committed
Update last access time of images when loaded from disk.
The OS doesn't automatically bump access time when reading files, so LRU would effectively be equivalent to "least recently downloaded" in SDWebImage.
1 parent d573278 commit 63c8d70

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

SDWebImage/Core/SDDiskCache.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ - (NSData *)dataForKey:(NSString *)key {
7171
}
7272
NSData *data = [NSData dataWithContentsOfFile:filePath options:self.config.diskCacheReadingOptions error:nil];
7373
if (data) {
74+
[[NSURL fileURLWithPath:filePath] setResourceValue:[NSDate date] forKey:NSURLContentAccessDateKey error:nil];
7475
return data;
7576
}
7677

7778
// fallback because of https://github.com/rs/SDWebImage/pull/976 that added the extension to the disk file name
7879
// checking the key with and without the extension
79-
data = [NSData dataWithContentsOfFile:filePath.stringByDeletingPathExtension options:self.config.diskCacheReadingOptions error:nil];
80+
filePath = filePath.stringByDeletingPathExtension;
81+
data = [NSData dataWithContentsOfFile:filePath options:self.config.diskCacheReadingOptions error:nil];
8082
if (data) {
83+
[[NSURL fileURLWithPath:filePath] setResourceValue:[NSDate date] forKey:NSURLContentAccessDateKey error:nil];
8184
return data;
8285
}
8386

0 commit comments

Comments
 (0)