Increment usage by arbitrary value #289
linusrachlis
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all and thanks for the work on this library 👋
I've come up twice against a specific limitation and I was wondering if someone has already considered and rejected this idea, or how difficult you think it would be.
I often find the need to increment the stored value by >1 when calling
get_usage()
. This happens when trying to protect an API that does something in bulk -- for example, think of an API that would create 2 todo items given the following request:Imagine if creating todos incurs some overhead to the system in proportion to how many individual items are created. In that case, to protect the system, I want to rate-limit this endpoint, but instead of incrementing by 1 for each request, I want to increment by the number of items in the payload.
Naively, it seems like this could be accomplished by:
delta=1
argument to get_usage()1
heredelta
argument for Django'scache.incr
here.Alternatively, the existing
increment
argument could be repurposed to a number, though that might be a breaking change.Regardless, I suggest an implementation only to illustrate for discussion purposes. My main question is, has this already been brought up before? Are you open to a PR doing the above? Are there issues with it that I don't see?
🙏 best wishes
Beta Was this translation helpful? Give feedback.
All reactions