Repository: LMCache/LMCache
File: lmcache/v1/config.py (Python)

Code before:
_CONFIG_DEFINITIONS: dict[str, dict[str, Any]] = {
    # Basic configurations
    "chunk_size": {"type": int, "default": 256, "env_converter": int},
    "local_cpu": {
        "type": bool,
        "default": True,
        "env_converter": lambda x: x.lower() in ["true", "1"],
    },
    "max_local_cpu_size": {"type": float, "default": 5.0, "env_converter": float},
    "local_disk": {
        "type": Optional[str],
        "default": None,
        "env_converter": _parse_local_disk,
    },
    "max_local_disk_size": {"type": float, "default": 0.0, "env_converter": float},
    "remote_url": {
        "type": Optional[str],
        "default": None,
        "env_converter": str,
    },
    "remote_serde": {"type": Optional[str], "default": "naive", "env_converter": str},
    # Feature toggles
    "use_layerwise": {
        "type": bool,
        "default": False,
        "env_converter": lambda x: x.lower() in ["true", "1"],
    },
    "save_decode_cache": {
        "type": bool,
        "default": False,
        "env_converter": lambda x: x.lower() in ["true", "1"],
    },
    "pre_caching_hash_algorithm": {
        "type": str,
        "default": "builtin",
        "env_converter": str,
    },
    # Blending configurations
    "enable_blending": {
        "type": bool,
        "default": False,
        "env_converter": lambda x: x.lower() in ["true", "1"],
    },
    "blend_recompute_ratio": {"type": float, "default": 0.15, "env_converter": float},
    "blend_min_tokens": {"type": int, "default": 256, "env_converter": int},
    "blend_special_str": {"type": str, "default": " # # ", "env_converter": str},
    # P2P configurations
    "enable_p2p": {
        "type": bool,
        "default": False,
        "env_converter": lambda x: x.lower() in ["true", "1"],

Review comment (refactor):
@Shaoting-Feng As this code duplicated so much time, would you like to abstract this into a `bool_converter` ?

You can referent to `_to_int_list`

Code after:
    "chunk_size": {"type": int, "default": 256, "env_converter": int},
    "local_cpu": {
        "type": bool,
        "default": True,
        "env_converter": lambda x: x
        if isinstance(x, bool)
        else str(x).lower() in ["true", "1"],
    },
    "max_local_cpu_size": {"type": float, "default": 5.0, "env_converter": float},
    "local_disk": {
        "type": Optional[str],
        "default": None,
        "env_converter": _parse_local_disk,
    },
    "max_local_disk_size": {"type": float, "default": 0.0, "env_converter": float},
    "remote_url": {
        "type": Optional[str],
        "default": None,
        "env_converter": str,
    },
    "remote_serde": {"type": Optional[str], "default": "naive", "env_converter": str},
    # Feature toggles
    "use_layerwise": {
        "type": bool,
        "default": False,
        "env_converter": lambda x: x
        if isinstance(x, bool)
        else str(x).lower() in ["true", "1"],
    },
    "save_decode_cache": {
        "type": bool,
        "default": False,
        "env_converter": lambda x: x
        if isinstance(x, bool)
        else str(x).lower() in ["true", "1"],
    },
    "pre_caching_hash_algorithm": {
        "type": str,
        "default": "builtin",
        "env_converter": str,
    },
    # Blending configurations
    "enable_blending": {
        "type": bool,
        "default": False,
        "env_converter": lambda x: x
        if isinstance(x, bool)
        else str(x).lower() in ["true", "1"],
    },
    "blend_recompute_ratio": {"type": float, "default": 0.15, "env_converter": float},
    "blend_min_tokens": {"type": int, "default": 256, "env_converter": int},