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

Item be evicted before reaching the TTL #358

Closed
cubicYYY opened this issue Dec 17, 2023 · 3 comments
Closed

Item be evicted before reaching the TTL #358

cubicYYY opened this issue Dec 17, 2023 · 3 comments

Comments

@cubicYYY
Copy link

let c = Cache::builder()
        .time_to_live(Duration::from_secs(60 * 60 * 24)) // live, 24h
        .build(),

I set my cache like this, make it unbounded.
This cache may be shared between threads.
However, I noticed that the items inserted will disappear very soon.
Is there an ensurance that items will always live longer than this TTL? How to let it expires after the TTL?

@cubicYYY
Copy link
Author

To be more specific:
I'm using it with actix-web.
At the beginning, it works fine:

let c = Cache::builder()
        .time_to_live(Duration::from_secs(60 * 60 * 24)) // live, 24h
        .build(),
let app = MyStruct{c};
HttpServer::new(move || {
        App::new()
            .app_data(web::Data::new(app.clone()))
//....

            }).bind(("0.0.0.0", 8888))?
    .run()
    .await;

But after I changed to:

let c = Cache::builder()
        .time_to_live(Duration::from_secs(60 * 60 * 24)) // live, 24h
        .build(),
HttpServer::new(move || {
        App::new()
            .app_data(web::Data::new(MyStruct{c})) // Now inside
//....

            }).bind(("0.0.0.0", 8888))?
    .run()
    .await;

And the problem occurs.

@cubicYYY
Copy link
Author

Is this a problem with the smart pointers, and maybe the underlying issue is something inside the unsafe impl Send/Sync ?

cubicYYY added a commit to cubicYYY/RIoT that referenced this issue Dec 17, 2023
@cubicYYY
Copy link
Author

The reason:
the worker threads will create a new state for each thread. So it must be done by ways like .clone()

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

1 participant