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.

Add `noself=True` parameter (equivalent to "aiocache" package)

See original GitHub issue

Source code for aiocache.decorators

    :param noself: bool if you are decorating a class function, by default self is also used to
        generate the key. This will result in same function calls done by different class instances
        to use different cache keys. Use noself=True if you want to ignore it.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Krukovcommented, Feb 11, 2022

@AIGeneratedUsername So I remade the decorator that @unmade suggested and we will have the next solution

from cashews import cache, noself
class MyClass:
    @noself(cache)(ttl="2h")
    async def get_name(self, user, version="v1"):
         ...

I described this in the documentation, can you take a look on it in the MR ? As you see my english not so well - so any comments are welcome

1reaction
Krukovcommented, Feb 7, 2022

I did research and I found an issue why this parameter was added to aiocache - aio-libs/aiocache#129 - nothing special, I mean that the there are no reason why method that need to be cached use self , but self is not used in value that will be in cache - it should be static or class method.

I have no doubt that it is useful for existing code, so I suggest that we can add workaround that @unmade made and put it to the documentation. We will have:

from cashews import cache, noself


class SampleClass:
  
   @noself(cache(ttl="1h"))
   async def(
       self,
       *args,
       **kwargs,
   ):
       ...

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caches — aiocache 0.11.1 documentation
Clears the cache in the cache namespace. If an alternative namespace is given, it will clear those ones instead. Parameters: namespace – str...
Read more >
aio-libs/aiocache: Asyncio cache manager for redis ... - GitHub
This library aims for simplicity over specialization. All caches contain the same minimum interface which consists on the following functions: add : Only...
Read more >
How to use the aiocache.cached function in aiocache - Snyk
To help you get started, we've selected a few aiocache.cached examples, based on popular ways it is used in public projects.
Read more >
Aiocache @cached decorator doesn't return the result
Finally I've found solution: I used always same parameter, so I should use key_builder without key parameter due to generate different keys ...
Read more >
aiocache 0.3.2 - PyPI
The operations supported by all backends are: add. get. set. multi_get. multi_set. delete ... Install the package with pip install aiocache. simple redis....
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