<s> import time <EOL> import logging <EOL> from hashlib import md5 <EOL> class RateLimiterFilter ( logging . Filter ) : <EOL> def filter ( self , record ) : <EOL> from django . conf import settings <EOL> from django . core . cache import cache <EOL> rate = getattr ( settings , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> prefix = getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> subject = record . getMessage ( ) <EOL> cache_key = "<STR_LIT>" % ( prefix , md5 ( subject ) . hexdigest ( ) ) <EOL> cache_count_key = "<STR_LIT>" % cache_key <EOL> result = cache . get_many ( [ cache_key , cache_count_key ] ) <EOL> value = result . get ( cache_key ) <EOL> cntr = result . get ( cache_count_key ) <EOL> if not cntr : <EOL> cntr = <NUM_LIT:1> <EOL> cache . set ( cache_count_key , cntr , rate + <NUM_LIT> ) <EOL> if value : <EOL> cache . incr ( cache_count_key ) <EOL> return False <EOL> record . msg = "<STR_LIT>" % ( cntr , record . msg ) <EOL> cache . set ( cache_key , time . time ( ) , rate ) <EOL> return True </s>
