-
Notifications
You must be signed in to change notification settings - Fork 154
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
Cache functions returning None
#452
Comments
Hi there, One use case where this could be useful is caching responses from a GraphQL server. We have a Sanic app that calls out to a GraphQL server. When a particular object can't be found, the GraphQL server returns a null, translating to None in Python land. |
Yep, I also thought on cases where calling a function triggers an expensive calculation and you don't want to trigger it if the endpoint is called after 5s or something like that. But not sure how common is that. But yes makes sense. you think this wrapper logic is something that could be reused? |
+1, same issue here. I think we could use a guard value internally ( |
In #652 we are looking to add a function to customise the behaviour needed to skip the cache. So, we should proceed with caching all results, then the old behaviour can be reproduced with |
Dogpile caching lib has a
https://dogpilecache.sqlalchemy.org/en/latest/api.html#dogpile.cache.region.CacheRegion.get |
We've added the |
Hey @Dreamsorcerer – I think that the caching of functions returning E.g. see this example which uses import asyncio
from aiocache import cached
@cached()
async def cached_returns_int() -> int:
print("executing cached_returns_int")
return 1
@cached()
async def cached_returns_none() -> None:
print("executing cached_returns_none")
return
async def test_caching() -> None:
for _ in range(5):
await cached_returns_int()
for _ in range(5):
await cached_returns_none()
asyncio.run(test_caching()) This prints:
I believe that's because receiving a cached value of aiocache/aiocache/decorators.py Lines 113 to 118 in 2877119
aiocache/aiocache/decorators.py Lines 147 to 152 in 2877119
|
Hmm, yeah. If you can create a test in a PR that'd be really helpful. |
Right now if you decorate a function that doesn't return anything, it will not work and will execute always, this is not intuitive
Is there a use case for this? could someone want to cache a function that doesn't return anything? happy to hear thoughts from people.
The text was updated successfully, but these errors were encountered: