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

Not clear expired content on CacheManager init #116

Closed
jlsandrin opened this issue Aug 22, 2017 · 8 comments
Closed

Not clear expired content on CacheManager init #116

jlsandrin opened this issue Aug 22, 2017 · 8 comments

Comments

@jlsandrin
Copy link

I'm using Cache to store JSON coming from the server. This content is updated everyday, so I'm setting it's expiration date to be the day it was downloaded at 11:59 PM. this works just fine and the content is expired and re downloaded the next day.

The problem I'm facing is that, due to business rules, I need to return expired content (so I can have something to show user), identify that this content has expired and download the new version. And then update view with this new content and cache it.

Is there any way to flag Cache to not clear expired data on initialization, and when receiving some notifications?

@zenangst
Copy link
Contributor

@jlsandrin hey man, right now we don't have a way of opting out from clearing the expired objects when CacheManager gets initialized. This is by design so that we don't keep outdated content around. With that said, couldn't you just set the expiration date to be nil when storing the objects? That way they won't be cleared when CacheManager initializes?

@zenangst
Copy link
Contributor

This feels pseudo related to #117.

@zenangst
Copy link
Contributor

zenangst commented Aug 28, 2017

@vadymmarkov could this be solved by adding a small configuration enum.

enum CacheExpirationMode {
  case auto, manual
}

.auto would be the default to not break the current implementation. And when you set it to .manual, it would simply opt out from doing any for of cleanup during application launch. This would mean that the developer would have to handle that manually (which I think is okay).

@vadymmarkov
Copy link
Contributor

@zenangst Yes, that should work I think.

@jlsandrin
Copy link
Author

I agree with clearing objects on init. I personally prefer an option like that, but unfortunately this app can't work this way.

The problem with setting the expiration to nil is that I can't handle if content is "old" or not (or at least I couldn't find a way). I download something new whenever expiration date is older than current date, while not deleting what is in store.

.manual option would be perfect for what I need.

@zenangst
Copy link
Contributor

@jlsandrin ohai, I whipped up a small PR to implement this feature, you can find it here #118

@jlsandrin
Copy link
Author

Awesome, you guys rock!

@zenangst
Copy link
Contributor

@jlsandrin let us know how it works out! It should be on master now. Closing the issue.

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

No branches or pull requests

3 participants