| 291 | return None |
| 292 | |
| 293 | def set_cache(self, key: str | None, value: CacheValue, local_only: bool = False, **kwargs: object): |
| 294 | model_type: Final = cast(type[BaseModel] | None, kwargs.pop("model_type", None)) |
| 295 | payload: Final[object] = CacheCodec.serialize(value, model_type=model_type) |
| 296 | shared: Final = self._shared |
| 297 | if shared is not None: |
| 298 | if key is None: |
| 299 | return None |
| 300 | try: |
| 301 | if local_only: |
| 302 | shared.set_local(key, payload, _ttl(kwargs)) |
| 303 | else: |
| 304 | shared.set_sync(key, payload, _ttl(kwargs)) |
| 305 | except Exception as e: # noqa: BLE001 # DualCache.set_cache swallows a failed write |
| 306 | verbose_proxy_logger.error("UserApiKeyCache.set_cache failed for key=%r: %s", key, e) |
| 307 | return None |
| 308 | if key is not None and is_user_key_cache_key(key): |
| 309 | return self.key_object_cache.set_cache(key=key, value=payload, local_only=local_only, **kwargs) |
| 310 | return super().set_cache(key=key, value=payload, local_only=local_only, **kwargs) |
| 311 | |
| 312 | async def async_set_cache(self, key: str | None, value: CacheValue, local_only: bool = False, **kwargs: object): |
| 313 | """Inside a request the Redis SET rides the request's pipeline (memory is written at once); anywhere |