-
Notifications
You must be signed in to change notification settings - Fork 24
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
Allow configured Cache in moka-store #26
Comments
I believe the original implementer mentioned it could probably be refactored to be more flexible. I would probably recommend rethinking Also worth noting that |
I tried implementing the Cache eviction on a time basis, but couldn't. It seems Moka expects, in its One way out could be running impl Expiry<Id, Record> for RecordExpiry {
fn expire_after_create(
&self,
_key: &Id,
value: &Record,
_created_at: std::time::Instant,
) -> Option<std::time::Duration> {
let expiry_date = value.expiry_date;
let now = OffsetDateTime::now_utc();
Some(if expiry_date <= now {
std::time::Duration::default()
} else {
(expiry_date - now).unsigned_abs()
})
}
} This (and also implementing the |
I think your proposed solution seems reasonable (it's certainly nicer to have the cache manage eviction for us). |
Nice, I'll work on it then. |
I finished my PR working on the cache eviction: #30. Now, I think I would like to work on allowing more of the builder configuration. I think we could provide, for example, a default The other options don't seem that useful to expose to the user at first glance. |
Another thing I thought about is using a hash better-suited for |
I'm not too familiar with moka (someone had contributed this store when they were bundled with tower-sessions) so I'll trust your judgement. At a high level making it so folks can provide arbitrary configuration of moka itself seems nice. |
What do you think about allowing
MokaStore
to be created using a built mokaCache
? I'm thinking of a new method implemented like this:I'm guessing maybe there are some configuration options for
Cache
that would not makeMokaStore
work correctly?I'm talking about this because the
new
method receiving anOption
felt awkward to me, because thenew
method ofCache
takes au64
directly. So I had to guess whatNone
would do.The text was updated successfully, but these errors were encountered: