bbangert / retools

Redis Tools
MIT License
138 stars 41 forks source link

Add cache decorator that spawns regenerate in the queue #3

Closed bbangert closed 10 years ago

bbangert commented 12 years ago

It would be useful if no one had to wait for long cache regenerations.

To do this, the CacheRegion should take another parameter that optionally returns the expiration time of the object. This way the cache_region decorator, when using regenerate=False can see if the value it gets back has expired.

If the object has expired, then it does a Redis get on a key to determine whether or not this has already been put in the queue for regenerating. If not, then it will add a queue task for regenerating the function with the appropriate arguments, and set the Redis key with a TTL at least 10 seconds longer than the estimated worst case function regeneration scenario. (To ensure its not enqueing the regeneration job too much).