Interesting approach.

Although, I don't like the "get multi" approach, too much overhead.

I personally prefer to configure an amount of time, combined with the max
hits, then do the following:

--------------------

class IPThrottleException(exception): pass
import time
MAX_INTERVAL = 180 # seconds
MAX_ATTEMPTS = 10
_t = time.time() # grab current ts
_t = int(_t / MAX_INTERVAL) # figure out which "period" we are in, based on
max interval
_ip = request.META.get('REMOTE_ADDR')
_key = "__ip_throttle__%s__%s" % (
    _t,
    _ip
)

_c = cache.get(_key)
if not c:
    cache.set(_key, 0)
    cache.incr(_key, 1)
elif _c > MAX_ATTEMPTS:
    raise IPThrottleException, "Max attempts reached"
else:
    cache.incr(_key, 1)



On Fri, Jul 8, 2011 at 5:53 PM, Jacob Kaplan-Moss <[email protected]>wrote:

> Hi folks --
>
> Also see http://simonwillison.net/2009/Jan/7/ratelimitcache/ for a
> discussion of a similar technique built on top of memcached.
>
> Jacob
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to