fastapi-cache icon indicating copy to clipboard operation
fastapi-cache copied to clipboard

Added event handlers and tests

Open calum-mcg opened this issue 4 years ago • 8 comments

Summary: Added optional custom event handlers for new_key and existing_key. Also added tests to cover the event handlers and custom key builder

Example For the events new_key and existing_key you can pass in a custom handler. By default there are no handlers.

Via a decorator:

@FastAPICache.on_event("existing_key")
def exists_in_cache(func, *args, **kwargs):
    print("Existing key")
    return None
@FastAPICache.on_event("new_key")
def new_in_cache(func, *args, **kwargs):
    print("New key set")
    return None

Via a class method:

def exists_in_cache(func, *args, **kwargs):
    print("Existing key")
    return None
def new_in_cache(func, *args, **kwargs):
    print("New key set")
    return None
FastAPICache.set_on_existing_key(exists_in_cache)
FastAPICache.set_on_new_key(new_in_cache)

calum-mcg avatar Sep 03 '21 17:09 calum-mcg

@long2ice - I've updated the PR based on your comments. Could you merge?

calum-mcg avatar Oct 11 '21 10:10 calum-mcg

@long2ice - any updates? Let me know if there are any other changes required

calum-mcg avatar Oct 18 '21 10:10 calum-mcg

OK, please resolve conflicting files

long2ice avatar Oct 18 '21 12:10 long2ice

Done!

calum-mcg avatar Oct 18 '21 19:10 calum-mcg

CI not pass, please merge master and try again

long2ice avatar Oct 19 '21 06:10 long2ice

Any movement on this? Would like to build off of it for some additional contributions.

mustyoshi avatar Mar 01 '22 14:03 mustyoshi

@long2ice - needs to run and pass CI workflow then can merge

calum-mcg avatar Mar 01 '22 14:03 calum-mcg

@long2ice - any updates on this?

calum-mcg avatar Mar 11 '22 10:03 calum-mcg