You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to use django-ratelimit to ratelimit same view with multiple limits:
defmultiple_rate_limit(key, rates):
""" Custom decorator to apply multiple rate limits to a view. 'rates' should be a list of rate limit strings, such as ['5/m', '100/h', '1000/d']. """defdecorator(view_func):
decorated_view=view_funcforrateinrates:
decorated_view=ratelimit(key=key, rate=rate)(decorated_view)
returndecorated_viewreturndecorator@multiple_rate_limit(key='user_or_ip', rates=['10/m', '300/30d'])defhome(request): #newreturnHttpResponse('<h1>Django Include URLs</h1>')
After calling the view first time the expire time is as below:
select * from cache_djrate ;
cache_key | value | expires
----------------------------------------+----------+------------------------
:1:rl:45b5d276e180f5b4f5d566ef01cfd472 | gAVLAS4= | 2023-07-10 17:40:38+06
:1:rl:41e758c64a2f25fe69295b778ca19be5 | gAVLAS4= | 2023-06-10 17:41:38+06
(2 rows)
So the monthly limit reflects correctly on expire time in the first row.
But, after calling the view again, these entries are manipulated as below:
select * from cache_djrate ;
cache_key | value | expires
----------------------------------------+----------+------------------------
:1:rl:45b5d276e180f5b4f5d566ef01cfd472 | gAVLAi4= | 2023-06-10 17:41:46+06
:1:rl:41e758c64a2f25fe69295b778ca19be5 | gAVLAi4= | 2023-06-10 17:41:46+06
(2 rows)
So, the first row expire time is no longer 1 month as expected.
Please check it.
Generally, multiple ratelimit this way is working and can block if count > limit.
But, the cache deletion mechanism seem to solely depend on expire time and number of entries with ratio.
So, if the expire time is 1 minute instead of 1 month as shown above, it might be deleted erroneously.
Similar expire time showing when only using monthly limit instead of multiple rate limits:
@ratelimit(group=None, key='user', rate='300/30d', method=ALL, block=True)defhome(request): #newreturnHttpResponse('<h1>Django Include URLs</h1>')
After calling view the first time:
djrate=# select * from cache_djrate ;
cache_key | value | expires
----------------------------------------+----------+------------------------
:1:rl:5d211ec5fef5dc09ea129067c38e9646 | gAVLAS4= | 2023-07-10 18:13:28+06
(1 row)
After calling the view the second time:
djrate=# select * from cache_djrate ;
cache_key | value | expires
----------------------------------------+----------+------------------------
:1:rl:5d211ec5fef5dc09ea129067c38e9646 | gAVLAi4= | 2023-06-10 18:14:29+06
The text was updated successfully, but these errors were encountered:
I tried to use django-ratelimit to ratelimit same view with multiple limits:
After calling the view first time the expire time is as below:
select * from cache_djrate ;
cache_key | value | expires
----------------------------------------+----------+------------------------
:1:rl:45b5d276e180f5b4f5d566ef01cfd472 | gAVLAS4= | 2023-07-10 17:40:38+06
:1:rl:41e758c64a2f25fe69295b778ca19be5 | gAVLAS4= | 2023-06-10 17:41:38+06
(2 rows)
So the monthly limit reflects correctly on expire time in the first row.
But, after calling the view again, these entries are manipulated as below:
select * from cache_djrate ;
cache_key | value | expires
----------------------------------------+----------+------------------------
:1:rl:45b5d276e180f5b4f5d566ef01cfd472 | gAVLAi4= | 2023-06-10 17:41:46+06
:1:rl:41e758c64a2f25fe69295b778ca19be5 | gAVLAi4= | 2023-06-10 17:41:46+06
(2 rows)
So, the first row expire time is no longer 1 month as expected.
Please check it.
Generally, multiple ratelimit this way is working and can block if count > limit.
But, the cache deletion mechanism seem to solely depend on expire time and number of entries with ratio.
So, if the expire time is 1 minute instead of 1 month as shown above, it might be deleted erroneously.
Similar expire time showing when only using monthly limit instead of multiple rate limits:
After calling view the first time:
djrate=# select * from cache_djrate ;
cache_key | value | expires
----------------------------------------+----------+------------------------
:1:rl:5d211ec5fef5dc09ea129067c38e9646 | gAVLAS4= | 2023-07-10 18:13:28+06
(1 row)
After calling the view the second time:
djrate=# select * from cache_djrate ;
cache_key | value | expires
----------------------------------------+----------+------------------------
:1:rl:5d211ec5fef5dc09ea129067c38e9646 | gAVLAi4= | 2023-06-10 18:14:29+06
The text was updated successfully, but these errors were encountered: