cache_on_arguements get does not respect expiration time
See original GitHub issueThe get
method attached by cache_on_arguements
does not respect the expiration_time
passed to cache_on_arguments
.
This leads to potentially bad behavior that decorated_method.get()
does not return NO_VALUE
when the cached value is older than expiration_time
, and the value it does return is different from the value that would have been retrieved by decorated_method()
. I can see this leading to quite tricky to solve bugs if the two ways of accessing the cache were used across a codebase.
If this is unintended behaviour then I would suggest decorated_method.get
pass expiration_time
to self.get
. Potentially it may also be wise to add a parameter to cache_on_arguements
to ignore expiration_time
on get
since that is a reasonable use case.
If intended it should be explicitly stated in the documentation to avoid confusion.
Example:
import datetime
from time import sleep
from dogpile.cache import make_region
my_region = make_region().configure('dogpile.cache.memory')
@my_region.cache_on_arguments(expiration_time=1)
def get_cached_datetime():
return datetime.datetime.now()
get_cached_datetime() # Returns current time (DateTime 1)
sleep(1)
get_cached_datetime.get() # Returns DateTime1 even though cache value should be invalidated
get_cached_datetime() # Returns current time (DateTime 2)
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (7 by maintainers)
sidenote: I think there should be a label dedicated to
cache_on_arguments
issues.Hey Mike, Thanks for the insightful and detailed response. I really appreciate you taking the time to school my naive butt :p
Given the state of ‘cache_on_arguements’ with all it inconsistencies, what would you think about adding a new decorator method and moving this one towards being deprecated? It would be backward compatible until the old method is removed, and it’s an obvious breaking change when the old method is removed. The obvious downsize is it bloats the interface and could be confusing for new users.
Interested in your thoughts on if cleaning this up is worth that cost?