-
Notifications
You must be signed in to change notification settings - Fork 47
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
Allow expiration_time to be a callable #20
Comments
Michael Bayer (zzzeek) wrote: fair enough, though do you think the callable is really only needed by |
David Beitey (davidjb) wrote: If you set a callable It does present potential for performance issues, but it would be on the user not to do something overly complicated in the callable. However, the expires callable could itself be cached by the user, too. Any other suggestions otherwise? |
Michael Bayer (zzzeek) wrote:
I'm not suggesting that the function be called immediately within the
yes, this is where we'd actually call the callable.
well only if a callable is presented. I'm just trying to avoid latency for the vast majority of use cases that only send a scalar value here. |
Changes by Michael Bayer (zzzeek):
|
Migrated issue, originally created by David Beitey (davidjb)
My current use-case is to cache a set of values for a relative amount of time -- in one case, until the end of the current day, in another, until the end of the given week, and finally, until a certain date/time.
Currently, dogpile.cache accepts an expiration_time as an integer, which represents a fixed number seconds from now (eg in 24 hours time), and not a relative or otherwise dynamic value. In order to obtain a relative
expiration_time
for use, you could useget_or_create
directly and calculate the necessary value when run, but for thecache_on_arguments
decorator, this isn't possible given its nature as a decorator.So, my suggestion is to allow
expiration_time
to be specified as callable that returns a integer and call this whenever expiration_time is used (eg in the CacheRegion.get and get_or_create functions). Thus, the expiration time is dynamic and since a function, the resulting relative time could be based upon anything (not just relative times as I mention above).For example:
The text was updated successfully, but these errors were encountered: