8000 Wrap functions in class with decorator · Issue #625 · aio-libs/aiocache · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Wrap functions in class with decorator #625
Open
@Dreamsorcerer

Description

@Dreamsorcerer

The decorator should be simplified to a simple function, which should then return an object which wraps the passed function. Something along the lines of:

class Wrapper:
    def __init__(self, func):
        self.func = func

    def __call__(self, *args, **kwargs):
        # Get from cache...
        # Or call self.func(*args, **kwargs)

def cached(func):
    return Wrapper(func)

This simplifies the logic, and makes it easy to add methods on to our function (related: #538). For example, to call the function while forcing the cache to update could look something like:

@cached
def foo(...):
    ...

# Force update
foo.refresh(...)
Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0