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.

alru_cache caches the created Task objects

See original GitHub issue

This test program prints Tasks: 101:

import asyncio
from async_lru import alru_cache
import random


@alru_cache(maxsize=100)
async def cached_test(arg):
    return arg


async def main():
    while True:
        arg = random.random()
        value = await cached_test(arg)
        assert arg == value
        print("Tasks: ", len(asyncio.Task.all_tasks()))


asyncio.run(main())

While it’s OK to wrap the coroutine in a Task, it is not OK to keep the Task around. It should be keeping only the arg and result in its cache, not the Task.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
hellysmilecommented, Jan 11, 2019

Should be fixed by https://pypi.org/project/async_lru/ 1.0.2 release

1reaction
hellysmilecommented, Jan 10, 2019

Hmm there might be a small "typo"

https://github.com/aio-libs/async_lru/pull/83 Give me some time to debug, that PR fixes Your issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

LRU Cache Implementation - GeeksforGeeks
Create a class LRUCache with declare a list of type int, an unordered map of type <int, list<int>>, and a variable to store...
Read more >
Implement LRU Cache - Educative.io
To implement an LRU cache we use two data structures: a hashmap and a doubly linked list. A doubly linked list helps in...
Read more >
LRU Cache Data Structure - Interview Cake
A Least Recently Used (LRU) Cache organizes items in order of use, allowing you to quickly identify which item hasn't been used for...
Read more >
Implement Least Recently Used (LRU) Cache - EnjoyAlgorithms
The least recently used (LRU) cache is one of the popular caching strategies, which defines the policy to discard the least recently used...
Read more >
lru-cache - npm
A cache object that deletes the least-recently-used items. Specify a max number of the most recently used items that you want to keep,...
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