mirror of
https://github.com/searxng/searxng.git
synced 2025-12-23 12:10:00 +00:00
add rate limiting per engine
This commit is contained in:
@@ -16,14 +16,28 @@ class SimpleSharedDict(shared_abstract.SharedDict):
|
||||
def get_int(self, key: str) -> Optional[int]:
|
||||
return self.d.get(key, None)
|
||||
|
||||
def set_int(self, key: str, value: int):
|
||||
def set_int(self, key: str, value: int, expire: Optional[int] = None):
|
||||
self.d[key] = value
|
||||
if expire:
|
||||
self._expire(key, expire)
|
||||
|
||||
def get_str(self, key: str) -> Optional[str]:
|
||||
return self.d.get(key, None)
|
||||
|
||||
def set_str(self, key: str, value: str):
|
||||
def set_str(self, key: str, value: str, expire: Optional[int] = None):
|
||||
self.d[key] = value
|
||||
if expire:
|
||||
self._expire(key, expire)
|
||||
|
||||
def _expire(self, key: str, expire: int):
|
||||
t = threading.Timer(expire, lambda k, d: d.pop(k), args=[key, self.d])
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
|
||||
def run_locked(func, *args):
|
||||
# SimpleSharedDict is not actually shared, so no locking needed
|
||||
return func(*args)
|
||||
|
||||
|
||||
def schedule(delay, func, *args):
|
||||
|
||||
Reference in New Issue
Block a user