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.

fix: functions without 'return' are not cached

See original GitHub issue

Reproducible code sample

import asyncio

from cashews import cache

cache.setup("mem://")


@cache(ttl="10m")
async def get():
    print("Start!")
    await asyncio.sleep(2)
    print("End!")
    # return "foobar"


async def func():
    await get()
    await get()


asyncio.run(func())

Expected behavior

Functions without ‘return’ must be cached. The same as Python’s ‘functools.cache’ decorator works.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Krukovcommented, Feb 11, 2022

@AIGeneratedUsername Thanks for you input, I on the same side with you. And you mentioned case where prefer to do not cache None, and I thought that is is more safer behavior. And now I think that I was wrong.

I’ll fix it

0reactions
Krukovcommented, Feb 13, 2022

Thanks - I enabled it, I am not familiar with it -let’s try

Read more comments on GitHub >

github_iconTop Results From Across the Web

python optional caching of function - Stack Overflow
I've a function which performs a database request and does not take any arguments. Most of the times it's okay if the function...
Read more >
cannot cache function that does not accept an argument #1390
Expected behavior: I expect the function to just be cached deterministically, as if I were using the lru_cache instead.
Read more >
@lru_cache on functions with no arguments - Google Groups
1. The functions Django wants to cache require Django to be initialized and the settings loaded. This means the return values are not...
Read more >
Memoizing recursive JavaScript functions (without mentioning ...
The trick here is that you're using side-effects. It's not possible to use your approach if the original function and the caching version...
Read more >
Reading and writing data to the cache - Apollo GraphQL Docs
If the cache is missing data for any of the query's fields, readQuery returns null . It does not attempt to fetch data...
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