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

TypeError: issubclass() arg 1 must be a class #870

Open
KaliCharan-V opened this issue Jul 3, 2024 · 2 comments
Open

TypeError: issubclass() arg 1 must be a class #870

KaliCharan-V opened this issue Jul 3, 2024 · 2 comments

Comments

@KaliCharan-V
Copy link

Installed latest version of aiocache: pip install aiocache
Code: cache = Cache(Cache.MEMORY)
Error: if not issubclass(cache_class, BaseCache):
TypeError: issubclass() arg 1 must be a class

@Dreamsorcerer
Copy link
Member

Unable to reproduce:

> pip3 install aiocache --upgrade
...
Successfully installed aiocache-0.12.2
> python3
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
>>> import aiocache
>>> aiocache.Cache(aiocache.Cache.MEMORY)
<aiocache.backends.memory.SimpleMemoryCache object at 0x7fcaa53a8c10>
>>>

@MeiHuaGuangShuo
Copy link

New version of aiocache==0.12.3 will not raise TypeError again at code cache = Cache(Cache.MEMORY)

But if you are using decorator to cache the result which you have seen a post ask you to do with the following code, the TypeError will raise at there again.

from aiocache import cached, Cache

cache = Cache(Cache.MEMORY)

@cached(cache=cache, ttl=3600)  # <-- Here
async def expensive_operation():
    await asyncio.sleep(5)
    return "result"

It's incorrect! According to the usage of official page, to work with decorator, you can directly give the Cache.MEMORY to cache parameter instead of Cache(Cahce.MEMORY)

Using the follow code can be useful(at least on my server)

from aiocache import cached, Cache

cache = Cache.MEMORY

@cached(cache=cache, ttl=3600)
async def expensive_operation():
    await asyncio.sleep(5)
    return "result"

Hope it will fix your problem

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

3 participants