This commit is contained in:
yeahyung 2025-04-24 00:55:42 -07:00 committed by GitHub
commit e2579f8824
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,6 +10,7 @@ Returns a UserAPIKeyAuth object if the API key is valid
import asyncio import asyncio
import re import re
import secrets import secrets
import time
from datetime import datetime, timezone from datetime import datetime, timezone
from typing import Optional, cast from typing import Optional, cast
@ -553,6 +554,18 @@ async def _user_api_key_auth_builder( # noqa: PLR0915
verbose_logger.debug("api key not found in cache.") verbose_logger.debug("api key not found in cache.")
valid_token = None valid_token = None
if (
valid_token is not None
and isinstance(valid_token, UserAPIKeyAuth)
and valid_token.last_refreshed_at is not None
and user_api_key_cache.default_in_memory_ttl is not None
and time.time() - valid_token.last_refreshed_at > user_api_key_cache.default_in_memory_ttl
):
user_api_key_cache.delete_cache(
key=hash_token(api_key)
)
valid_token = None
if ( if (
valid_token is not None valid_token is not None
and isinstance(valid_token, UserAPIKeyAuth) and isinstance(valid_token, UserAPIKeyAuth)