fastapi-cache
fastapi-cache copied to clipboard
Added event handlers and tests
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)
@long2ice - I've updated the PR based on your comments. Could you merge?
@long2ice - any updates? Let me know if there are any other changes required
OK, please resolve conflicting files
Done!
CI not pass, please merge master and try again
Any movement on this? Would like to build off of it for some additional contributions.
@long2ice - needs to run and pass CI workflow then can merge
@long2ice - any updates on this?