Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageCache: expiration date #381

Closed
lonsky opened this issue Aug 2, 2016 · 3 comments
Closed

ImageCache: expiration date #381

lonsky opened this issue Aug 2, 2016 · 3 comments

Comments

@lonsky
Copy link

lonsky commented Aug 2, 2016

@onevcat

Is it possible to extend expiration date for cached image on the disk?

When I try to store the same file with the same key it seems like nothing happens.

Maybe something like this could be helpful for ImageCache class:

func touch(cacheKey: String)    //updates modified date

also it could be useful to call this method when you load file from cache (retrieveImageForKey).

in this case recently used files won't expire

@onevcat
Copy link
Owner

onevcat commented Aug 7, 2016

Kingfisher is using the modification date of a file to determine the expiration. So you should be able to extend the date by modify the file. Did you try to remove that cache first and then store the same file again? (I am not sure whether it could work though..)

Maybe we should use the access day instead of modification date to check the expiration. It might work better. How do you think about it?

@lonsky
Copy link
Author

lonsky commented Aug 8, 2016

@onevcat thank you for reply and for great framework!

remove/add should work. but it's not neat solution :)

i can think about two different cache strategies:

  1. (the current one) image file (or group of file) after downloading has limited lifetime (equal maxCachePeriodInSecond) before subsequent download of new version of file.
    With this strategy image file will have fixed expiration date: expirationDate = downloadTime + maxCachePeriodInSecond and will be removed even if it was used recently.

  2. image file (or group of file) after downloading modify its NSFileModificationDate attribute while being accessed via retrieveImageForKey.
    With this strategy image file will shift its expiration date every time it is accessed and "garbage collector" will remove only unused/less used files.
    Also, as "side effect", if cache will run out of available free space, it's possible to remove less relevant files first.

maybe it can be a property that will allow to switch between these strategies

@onevcat
Copy link
Owner

onevcat commented Aug 17, 2016

Use access date instead of modification date. So, just access that image from disk will extend the expiration date for the same. Implemented in #406

@onevcat onevcat closed this as completed Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants