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

Unexpected TTL behavior for in-memory backend #423

Closed
minhtule opened this issue Nov 9, 2018 · 2 comments
Closed

Unexpected TTL behavior for in-memory backend #423

minhtule opened this issue Nov 9, 2018 · 2 comments

Comments

@minhtule
Copy link
Contributor

minhtule commented Nov 9, 2018

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 asyncio
import 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?

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.

@argaen
Copy link
Member

argaen commented Nov 10, 2018 via email

@argaen
Copy link
Member

argaen commented Nov 13, 2018

Fixed with #424

@argaen argaen closed this as completed Nov 13, 2018
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

2 participants