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

have memoize recalculate in background before it's needed #5

Closed
aaronsw opened this issue Mar 3, 2010 · 5 comments
Closed

have memoize recalculate in background before it's needed #5

aaronsw opened this issue Mar 3, 2010 · 5 comments

Comments

@aaronsw
Copy link
Contributor

aaronsw commented Mar 3, 2010

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.

@anandology
Copy link
Member

What do you mean by just before? It is possible to trigger recomputation only when the function is called.

@aaronsw
Copy link
Contributor Author

aaronsw commented Mar 4, 2010

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.

@anandology
Copy link
Member

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.

@aaronsw
Copy link
Contributor Author

aaronsw commented Mar 4, 2010

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.

@aaronsw
Copy link
Contributor Author

aaronsw commented Mar 27, 2010

I convinced myself.

This issue was closed.
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

2 participants