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

Add an example to show how to run pending tasks in an interval #379

Open
tatsuya6502 opened this issue Jan 19, 2024 · 3 comments
Open

Add an example to show how to run pending tasks in an interval #379

tatsuya6502 opened this issue Jan 19, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@tatsuya6502
Copy link
Member

Split from #349 (comment)

Hi. It does not have to be run_pending_tasks method, but you need to call some of the cache methods such as get, get_with, insert, or remove to drive eviction_listener.

Before v0.12.0, Moka had its own global thread pool to periodically run pending tasks. Some users did not like it, so we removed it. You will find more details here when pending tasks (internal maintenance tasks) will be executed: https://github.com/moka-rs/moka/blob/main/MIGRATION-GUIDE.md#the-maintenance-tasks

but i want the eviction_listener() to be called exactly at the time of eviction, not some time later,

can you please help me to understand what should i do?

You can spawn a thread and make it to call run_pending_tasks with some interval (e.g. 0.1 secs). If you need some code samples, I could write one for you.

@tatsuya6502 tatsuya6502 added the documentation Improvements or additions to documentation label Jan 19, 2024
@tatsuya6502
Copy link
Member Author

CC: @unikzforce

@unikzforce
Copy link

Thanks

@agiuliano
Copy link

Hi! would it be good to add in the public doc about this behavior when it's described how to create an eviction listener? I feel it'd be good to say explicitly that the listener is not called automatically but it's linked to some cache operations, and perhaps bring the section in https://github.com/moka-rs/moka/blob/main/MIGRATION-GUIDE.md#the-maintenance-tasks to the pub doc as well?

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

No branches or pull requests

3 participants