GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Supports LRU eviction on disk cache, change the default expire type to accessDate instead of modificationDate by timonus · Pull Request #3759 · SDWebImage/SDWebImage

Conversation

@timonus

@timonus timonus commented Oct 7, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found none

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

Pull Request Description

NSFileManager does not automatically increment access date when reading files off disk, which means that use of SDImageCacheConfigExpireTypeAccessDate is effectively identical to using SDImageCacheConfigExpireTypeCreationDate. This doesn't seem like the correct behavior on SDWebImage's part, and it isn't what's documented here. This PR makes it so that SDWebImage adjusts the file content access date when files are read off disk to address the issue.

I've also added a commit that updates the default cache behavior to SDImageCacheConfigExpireTypeAccessDate since I believe that's what's commonly expected. People generally want cache purging by time-of-use in my experience instead of using the time the file was downloaded at. If you strongly disagree I can omit that change!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@timonus timonus changed the title Fix issue causing SDWebImage disk cache eviction LRU to not function as expected. Fix issue causing disk cache eviction LRU to not function as expected. Oct 7, 2024
@timonus

timonus commented Oct 7, 2024

Copy link
Copy Markdown
Contributor Author

I have done this in my image loading library for quite a long time (though I used to use modification date) https://github.com/timonus/TJImageCache/blob/main/TJImageCache/TJImageCache.m#L196

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dreampiggy

dreampiggy commented Oct 8, 2024

Copy link
Copy Markdown
Contributor

Sounds great. I'll have a check later.

Actually these code was not changed at least 5 years...😂 So it's broken at the beginning ?

timonus reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dreampiggy
dreampiggy reviewed Oct 8, 2024
View reviewed changes
Comment thread SDWebImage/Core/SDDiskCache.m
}
NSData *data = [NSData dataWithContentsOfFile:filePath options:self.config.diskCacheReadingOptions error:nil];
if (data) {
[[NSURL fileURLWithPath:filePath] setResourceValue:[NSDate date] forKey:NSURLContentAccessDateKey error:nil];

@dreampiggy dreampiggy Oct 8, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this time consuming ?

If so, need a extra if (self.config.diskCacheExpireType == SDImageCacheConfigExpireTypeAccessDate) guard

If not, it's OK

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@timonus timonus Oct 8, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is quite fast, significantly faster than the data read in my (very quick) testing.

Screenshot 2024-10-08 at 11 12 33 AM

Logged times are (1) time to read data, (2) time to write content access date, and (3) 2/1

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
dreampiggy
dreampiggy reviewed Oct 8, 2024
View reviewed changes
Comment thread SDWebImage/Core/SDImageCacheConfig.m
_diskCacheWritingOptions = NSDataWritingAtomic;
_maxDiskAge = kDefaultCacheMaxDiskAge;
_maxDiskSize = 0;
_diskCacheExpireType = SDImageCacheConfigExpireTypeModificationDate;

@dreampiggy dreampiggy Oct 8, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to change default value, but this PR will marked as Behavior Changes and I'll point this on release changelog

Actually I don't know why the original author use modifyas expire type, since it's not actually LRU (we usually don't write to same cache key image)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

timonus reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@dreampiggy dreampiggy added Behavior Changes cache Anything related to Cache System labels Oct 8, 2024
@dreampiggy dreampiggy added this to the 5.20.0 milestone Oct 8, 2024
@dreampiggy

dreampiggy commented Oct 9, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Can you rebase and run the test cases again (or update the test case with your changes, since you change the default value)

The master branch fix the CI issue

timonus reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

timonus added 2 commits October 9, 2024 10:13
@timonus
Update last access time of images when loaded from disk.
63c8d70
The OS doesn't automatically bump access time when reading files, so LRU would effectively be equivalent to "least recently downloaded" in SDWebImage.
@timonus
Update default disk cleaning method to use content access date.
e524ca0
This is possibly controversial, but I suspect most clients of SDWebImage would prefer files purged based on their last time of use instead of the date when they were downloaded.
@timonus
timonus force-pushed the lru-upstream branch from cfae4dd to e524ca0 Compare October 9, 2024 17:16
@timonus

timonus commented Oct 9, 2024

Copy link
Copy Markdown
Contributor Author

Alright, rebased and linting seems to pass. It looks like unit tests are all failing to build but I don't think that's caused by the contents of this PR. I updated the one test that referenced modified date here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@timonus

timonus commented Oct 11, 2024

Copy link
Copy Markdown
Contributor Author

@dreampiggy anything I can do to nudge this along? I'm unable to run the tests locally without installing Cocoapods, which I need to make other changes for and I'd rather not do. I don't think the tests are failing due to my change but if they are could you let me know?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dreampiggy

dreampiggy commented Oct 12, 2024

Copy link
Copy Markdown
Contributor

The SDWebImageTestCache.m has compile error, seems I can fix this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dreampiggy
dreampiggy reviewed Oct 12, 2024
View reviewed changes
Comment thread Tests/Tests/SDWebImageTestCache.m Resolved

Uh oh!

There was an error while loading. Please reload this page.

dreampiggy
dreampiggy reviewed Oct 12, 2024
View reviewed changes
Comment thread Tests/Tests/SDWebImageTestCache.m Resolved

Uh oh!

There was an error while loading. Please reload this page.

timonus and others added 2 commits October 11, 2024 20:21
@timonus @dreampiggy
Update SDWebImageTestCache.m
dcd0c46
Co-authored-by: DreamPiggy <[email protected]>
@timonus @dreampiggy
Update SDWebImageTestCache.m
0cde158
Co-authored-by: DreamPiggy <[email protected]>
@timonus

timonus commented Oct 12, 2024

Copy link
Copy Markdown
Contributor Author

Ah, thank you! Sorry I didn't catch that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dreampiggy

dreampiggy commented Oct 12, 2024

Copy link
Copy Markdown
Contributor

Merge for now. But the release date of 5.20 may be delayed due to other break changes I want to added.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dreampiggy
dreampiggy merged commit 0b10fcb into SDWebImage:master Oct 12, 2024
@dreampiggy dreampiggy changed the title Fix issue causing disk cache eviction LRU to not function as expected. Supports LRU eviction on disk cache, change the default expire type to accessDate instead of modificationDate Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dreampiggy dreampiggy dreampiggy left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Behavior Changes cache Anything related to Cache System

Projects

None yet

Milestone

5.20.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@timonus @dreampiggy
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.