question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cache_on_arguements get does not respect expiration time

See original GitHub issue

The 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:open
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jvanascocommented, Jan 20, 2020

sidenote: I think there should be a label dedicated to cache_on_arguments issues.

1reaction
airstandleycommented, Apr 23, 2019

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Tell Whether Expired Food Is Safe to Eat
As a general rule of thumb, most canned foods (for example, canned tuna, soups, and vegetables) can be stored for two to five...
Read more >
Extend an Expiration Date or Renew an Expired Job Posting
Active jobs: For currently active postings, an email notification is sent to the original job poster three days prior to a job expiring,...
Read more >
Does a Sunscreen Stay Effective After Its Expiration Date?
If you can't find an expiration date on the product you're using, you should mark the month and year you purchased it.
Read more >
16 CFR § 803.7 - Expiration of notification. - Law.Cornell.Edu
Notification with respect to an acquisition shall expire 1 year following the expiration of the waiting period. If the acquiring person's holdings do...
Read more >
Drug Expiration Dates — Do They Mean Anything?
Are expired drugs safe and does the medicine expiration date really matter? ... expiration date on a drug does stand for something, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found