-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Moka loses cache with curl #299
Comments
It's looking like this is a lazy_static issue. Since it's being deprecated, I've switched the cache to once_cell. Seems to be working. I'm reserving the right to re-open this once I've cleaned up the carnage. |
It's the implementation of expire_after() that conflicts with curl. Somehow. I expect I'll have to switch to a different cache manager now. moka is simply too opaque. I doubt this will lead to any insight, but here's a log:
The cache evaporates when it runs into the wall of curl. |
Hi. Thanks you for trying moka. Looking at the log, I think you still have the Can you please tell us what you are trying to achieve with the Expiry? What is the expected behavior? If you need, I will write some sample code. Also, I am not sure how curl crate is used. Are you storing something returned by curl to the cache? |
Hi - Thanks for the reply! I've spent several days battling this issue. My apologies in advance if my replies seem curt.
Yes, it's a short expiry time. It's meant to simulate real time. I pushed the TTL and it still disappears:
I want to track 4 different activities across at least 28 days. The cache must also be saved across image activations. I have the serialization/deserialization working. If I mock up the curl call, the Expiry trait works as expected. I am not storing anything from the call in the cache. Here is a snipped version of the code that produces the log:
Here's the current Expiry impl
Here's the mocked version of the code that demonstrate Expiry works as expected in the absence of curl
Here's the log:
|
Hi!
Sorry for hearing that. I see you are struggling with translating per-activity-token TTI and TTL into the Expiry trait methods. How about the following pub struct ACExpiry;
impl ACExpiry {
fn tti(&self, activity: &Activity) -> Duration {
// TODO: Return the TTI for the activity.token. (e.g. TWO_DAYS)
todo!()
}
fn ttl(&self, activity: &Activity) -> Duration {
// TODO: Return the TTL for the activity.token. (e.g. TWENTYEIGHT_DAYS)
todo!()
}
}
impl Expiry<Activity, Duration> for ACExpiry {
fn expire_after_create(
&self,
activity: &Activity,
_activity_ttl: &Duration,
_current_time: Instant,
) -> Option<Duration> {
Some(self.tti(activity))
}
fn expire_after_update(
&self,
activity: &Activity,
_activity_ttl: &Duration,
_current_time: Instant,
_current_duration: Option<Duration>,
) -> Option<Duration> {
Some(self.tti(activity))
}
fn expire_after_read(
&self,
activity: &Activity,
_activity_ttl: &Duration, // I am not sure what to do with this.
current_time: Instant,
_current_duration: Option<Duration>,
last_modified_at: Instant,
) -> Option<Duration> {
let tti = self.tti(activity);
let ttl = self.ttl(activity);
// Age is the duration since this activity was created or updated.
let age = current_time.duration_since(last_modified_at);
if age + tti < ttl {
// Current age + TTI is shorter than TTL, so we can extend the
// expiry by TTI.
Some(tti)
} else if age < ttl {
// Current age is shorter than TTL, so we can extend the expiry
// by the remaining duration until TTL. (The remaining duration
// should be shorter than TTI)
Some(ttl - age)
} else {
// Already lived longer than or equal to TTL. Expire now.
Some(Duration::default())
}
}
} I am not a native English speaker and I believe the documents I wrote for moka have some places to improve. I will try to make it better over time, but if you have any questions or suggestions, please feel free to open a GH discussion, issue or PR. |
Following up my previous post.
The reason the cached entry disappeared at "2 Mutex" is that
Calling real curl would take longer than 49.871588ms, so the entry expired while calling curl. This is why the entry disappeared. You should try my |
Ok, thanks for the effort! I will implement and repost. |
Thanks! Worked out of the box. |
I am glad to hear that you got it working!
Sure. I will follow it up with this: |
The cache gets lost when using crate
curl
.I'm guessing it has something to do with curl's memory management when sending data.
mini-moka doesn't have this problem. However, I lose the Expiry trait. If this bug attracts any interest, I will work up a reproducer; which is a fairly significant time suck if there's no sympathy in working this issue. I'd rather spend my time working around the loss of Expiry.
The text was updated successfully, but these errors were encountered: