(fix) improve proxy api_key caching

This commit is contained in:
ishaan-jaff 2024-02-02 19:59:13 -08:00
parent ae95e4c3f9
commit cfec3c611e

View file

@ -528,10 +528,9 @@ async def user_api_key_auth(
# Token passed all checks
api_key = valid_token.token
hashed_token = hash_token(api_key)
# Add hashed token to cache
user_api_key_cache.set_cache(key=hashed_token, value=valid_token, ttl=60)
user_api_key_cache.set_cache(key=api_key, value=valid_token, ttl=60)
valid_token_dict = _get_pydantic_json_dict(valid_token)
valid_token_dict.pop("token", None)
"""
@ -1455,6 +1454,7 @@ async def generate_key_helper_fn(
saved_token["expires"] = saved_token["expires"].isoformat()
if key_data["token"] is not None and isinstance(key_data["token"], str):
hashed_token = hash_token(key_data["token"])
saved_token["token"] = hashed_token
user_api_key_cache.set_cache(
key=hashed_token,
value=LiteLLM_VerificationToken(**saved_token), # type: ignore