-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
have memoize recalculate in background before it's needed #5
Comments
What do you mean by just before? It is possible to trigger recomputation only when the function is called. |
The first time you do the calculation, count how much time it takes (time_elapsed). Then spawn a thread, have it sleep(expires - time_elapsed) and then do the computation. Repeat. |
So you want to start as many threads as there are items in the cache? Should it keep on recomputing after each timeout even though is not accessed? It looks too complicated and inefficient to me. |
I was only hoping to use it in cases where the function takes no arguments. The typical case I run into is that there's a database query which takes a little bit to do but the results are used on every page load. One wants to do the database query on a schedule, not on every page load. But maybe the solution is just to use background=True with a smaller expires time. |
I convinced myself. |
Right now using memoize with background=True, if you ask for a result that's expired, it'll recalculate it in a new thread but send you the old result. It'd be nice if there was an option to have an ongoing thread that would recalculate the answer just before it expired.
The text was updated successfully, but these errors were encountered: