mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
(#9820) expire user api key cache
This commit is contained in:
parent
8ecd9ede81
commit
4e07386044
1 changed files with 13 additions and 0 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue