-
Notifications
You must be signed in to change notification settings - Fork 158
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
Unexpected TTL behavior for in-memory backend #423
Comments
Oh, true, the handler gets overridden but doesn't get cancelled. Good
catch.
I don't have access to a laptop this weekend. Will have a look at the PR on
Monday and do a bug fix release
…On Fri, Nov 9, 2018, 16:28 Minh Tu Le ***@***.***> wrote:
For the in-memory backend, when I set a new value, the old TTL timer
didn't get cancel and the new value is removed before its new TTL is
expired.
The issue can be reproduced as follow.
import asyncioimport aiocache
async def print_key(cache, key):
value = await cache.get(key)
print(f'cached value {value}')
async def main():
in_mem_cache = aiocache.caches.get('default')
await in_mem_cache.set('foo', 100, ttl=2)
await asyncio.sleep(1)
await print_key(in_mem_cache, 'foo') # 100
await in_mem_cache.set('foo', 200, ttl=2) # This should reset the key's TTL
await asyncio.sleep(1)
await print_key(in_mem_cache, 'foo') # None! It should display the new value 200.
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
When I setup the default cache with a Redis backend, the 2nd print result
is 200 as one would expect. So is this current behavior expected for the
in-memory backend?
I made this change
<minhtule@6016904>
to cancel the existing TTL timer before setting the value and the in-memory
behaves just like Redis.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#423>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADaZKo4Ag2o-gAI1X9kFoCn78lBDYtR9ks5utZ82gaJpZM4YWxx2>
.
|
Fixed with #424 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the in-memory backend, when I set a new value, the old TTL timer didn't get cancel and the new value is removed before its new TTL is expired.
The issue can be reproduced as follow.
When I setup the
default
cache with a Redis backend, the 2nd print result is200
as one would expect. So is this current behavior expected for the in-memory backend?If it's a bug, I have this PR to cancel the existing TTL timer before setting the value and the in-memory behaves just like Redis.
The text was updated successfully, but these errors were encountered: