class SimpleRateThrottle(BaseThrottle): (source)
Known subclasses: rest_framework.throttling.AnonRateThrottle
, rest_framework.throttling.ScopedRateThrottle
, rest_framework.throttling.UserRateThrottle
A simple cache implementation, that only requires `.get_cache_key()` to be overridden. The rate (requests / seconds) is set by a `rate` attribute on the Throttle class. The attribute is a string of the form 'number_of_requests/period'. Period should be one of: ('s', 'sec', 'm', 'min', 'h', 'hour', 'd', 'day') Previous request information used for throttling is stored in the cache.
Method | __init__ |
Undocumented |
Method | allow |
Implement the check to see if the request should be throttled. |
Method | get |
Should return a unique cache-key which can be used for throttling. Must be overridden. |
Method | get |
Determine the string representation of the allowed request rate. |
Method | parse |
Given the request rate string, return a two tuple of: <allowed number of requests>, <period of time in seconds> |
Method | throttle |
Called when a request to the API has failed due to throttling. |
Method | throttle |
Inserts the current request's timestamp along with the key into the cache. |
Method | wait |
Returns the recommended next request time in seconds. |
Class Variable | cache |
Undocumented |
Class Variable | scope |
Undocumented |
Instance Variable | duration |
Undocumented |
Instance Variable | history |
Undocumented |
Instance Variable | key |
Undocumented |
Instance Variable | now |
Undocumented |
Instance Variable | num |
Undocumented |
Instance Variable | rate |
Undocumented |
Inherited from BaseThrottle
:
Method | get |
Identify the machine making the request by parsing HTTP_X_FORWARDED_FOR if present and number of proxies is > 0. If not use all of HTTP_X_FORWARDED_FOR if it is available, if not use REMOTE_ADDR. |
rest_framework.throttling.ScopedRateThrottle
Implement the check to see if the request should be throttled. On success calls `throttle_success`. On failure calls `throttle_failure`.
rest_framework.throttling.AnonRateThrottle
, rest_framework.throttling.ScopedRateThrottle
, rest_framework.throttling.UserRateThrottle
Should return a unique cache-key which can be used for throttling. Must be overridden. May return `None` if the request should not be throttled.
Given the request rate string, return a two tuple of: <allowed number of requests>, <period of time in seconds>