Skip to content

[QUESTION] Is there an ability to run a function when the cache is used or key is set? #34

Open
@calum-mcg

Description

@calum-mcg

Is it possible to run a function whenever a cache is used or cache key is set? Ideally something similar to the custom_key_coder , for example:

def key_set_function(
    func,
    namespace: Optional[str] = "",
    request: Request = None,
    response: Response = None,
    *args,
    **kwargs,
):
    // Do something
    return something

@app.get("/")
@cache(expire=60, coder=JsonCoder , key_set_handler=key_set_function)
async def index(request: Request, response: Response):
    return dict(hello="world")

I'm aware of aiocache having hooks which are implemented via 'plugins' that you can run before and after a new key is set. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions