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

Add an option to reset remove timer on access #47

Open
ghost opened this issue Mar 30, 2021 · 1 comment
Open

Add an option to reset remove timer on access #47

ghost opened this issue Mar 30, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 30, 2021

For exemple:

from expiringdict import ExpiringDict
import time
cache = ExpiringDict(max_len=10, max_age_seconds=10, refresh_on_access=True)
cache["foo"] = "bar"
time.sleep(7)
print(cache["foo"]) #Value is accessed, timer is reset for this value
time.sleep(7)
print(cache["foo"]) #Value is still there

Alternatively, a function to reset the timer

from expiringdict import ExpiringDict, ResetTimer
import time
cache = ExpiringDict(max_len=10, max_age_seconds=10)
cache["foo"] = "bar"
time.sleep(7)
ResetTimer(cache, "foo") #Timer is reset for this value
time.sleep(7)
print(cache["foo"]) #Value is still there
@ghost
Copy link
Author

ghost commented Mar 30, 2021

Actually this code works:

cache["test"] = "desuwa"
time.sleep(7)
cache["test"] = cache["test"]
time.sleep(7)
print(cache['test'])

So the second example is already possible

It would be nice to be able to do this on access automatically though, like in the first example

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

0 participants