新增了Alexa渠道的所有核心功能模块,包括配置管理、请求校验、会话管理、安全验证、去重、响应格式化、渐进式响应、主动推送、提醒功能、配对绑定以及Webhook端点,并完成了插件注册和配置项定义。
34 lines
797 B
Python
34 lines
797 B
Python
import time
|
|
from collections import OrderedDict
|
|
|
|
|
|
class AlexaDeduplicator:
|
|
|
|
MAX_ENTRIES = 500
|
|
TTL_SECONDS = 300
|
|
|
|
def __init__(self):
|
|
self._cache: OrderedDict[str, float] = OrderedDict()
|
|
|
|
def is_duplicate(self, request_id: str) -> bool:
|
|
if not request_id:
|
|
return False
|
|
|
|
now = time.time()
|
|
|
|
while self._cache:
|
|
oldest_key, oldest_time = next(iter(self._cache.items()))
|
|
if now - oldest_time > self.TTL_SECONDS:
|
|
self._cache.popitem(last=False)
|
|
else:
|
|
break
|
|
|
|
if request_id in self._cache:
|
|
return True
|
|
|
|
self._cache[request_id] = now
|
|
|
|
while len(self._cache) > self.MAX_ENTRIES:
|
|
self._cache.popitem(last=False)
|
|
|
|
return False |