{"record":{"id":"16ae0039ac7cffd5","repo":"BerriAI/litellm","slug":"please-install-litellm-with-litellm-caching-to","errorCode":null,"errorMessage":"Please install litellm with `litellm[caching]` to use disk caching.","messagePattern":"Please install litellm with `litellm\\[caching\\]` to use disk caching\\.","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"litellm/caching/disk_cache.py","lineNumber":19,"sourceCode":"import json\nfrom typing import TYPE_CHECKING, Any, Final\n\nfrom .base_cache import BaseCache\n\nif TYPE_CHECKING:\n    from opentelemetry.trace import Span as _Span\n\n    Span = _Span | Any\nelse:\n    Span = Any\n\n\nclass DiskCache(BaseCache):\n    def __init__(self, disk_cache_dir: str | None = None):\n        try:\n            import diskcache as dc\n        except ModuleNotFoundError as e:\n            raise ModuleNotFoundError(\"Please install litellm with `litellm[caching]` to use disk caching.\") from e\n\n        # if users don't provider one, use the default litellm cache\n        if disk_cache_dir is None:\n            self.disk_cache = dc.Cache(\".litellm_cache\")\n        else:\n            self.disk_cache = dc.Cache(disk_cache_dir)\n\n    def set_cache(self, key, value, **kwargs):\n        if \"ttl\" in kwargs:\n            self.disk_cache.set(key, value, expire=kwargs[\"ttl\"])\n        else:\n            self.disk_cache.set(key, value)\n\n    async def async_set_cache(self, key, value, **kwargs):\n        self.set_cache(key=key, value=value, **kwargs)\n\n    async def async_set_cache_pipeline(self, cache_list, **kwargs):\n        for cache_key, cache_value in cache_list:","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/caching/disk_cache.py#L1-L37","documentation":"ModuleNotFoundError raised by DiskCache.__init__ when the 'diskcache' package is not installed. LiteLLM's disk cache backend is an optional dependency; constructing litellm.Cache(type='disk') (or s3-disk variants) imports diskcache lazily and converts the failure into an actionable install hint. The original ImportError is chained via `from e`.","triggerScenarios":"Configuring litellm.cache = litellm.Cache(type=\"disk\", disk_cache_dir=...) (or \"s3-disk\") in an environment where the diskcache extra is not installed, or type=\"disk\" in proxy config cache block without the optional dependency.","commonSituations":"Fresh installs with plain pip install litellm (extras not included); Docker images trimmed of optional deps; upgrading LiteLLM and the optional extra name changed; CI environments diverging from local.","solutions":["Install the extra: pip install 'litellm[caching]' (or pip install diskcache directly).","Alternatively use a cache backend you already have, e.g. litellm.Cache(type=\"redis\", host=...).","Pin the extra in requirements.txt/pyproject so deploys match local."],"exampleFix":"# before\nlitellm.cache = litellm.Cache(type=\"disk\")  # ModuleNotFoundError\n\n# after (shell)\n# pip install 'litellm[caching]'\nlitellm.cache = litellm.Cache(type=\"disk\")","handlingStrategy":"validation","validationCode":"def ensure_disk_cache_available() -> None:\n    try:\n        import diskcache  # noqa: F401\n    except ModuleNotFoundError as e:\n        raise RuntimeError(\"Run: pip install 'litellm[caching]'\") from e","typeGuard":"def disk_cache_available() -> bool:\n    try:\n        import diskcache  # noqa: F401\n        return True\n    except ModuleNotFoundError:\n        return False","tryCatchPattern":"try:\n    litellm.cache = litellm.Cache(type=\"disk\", disk_cache_dir=\"./.litellm_cache\")\nexcept ModuleNotFoundError as e:\n    logger.warning(\"disk cache unavailable (%s); falling back to in-memory\", e)\n    litellm.cache = litellm.Cache(type=\"local\")","preventionTips":["Declare extras in your deploy manifests: litellm[caching] wherever disk cache is used.","Add a dependency check at app startup before configuring the cache.","Keep Docker/CI dependency files in sync with the cache backend you choose."],"tags":["caching","disk-cache","dependencies","installation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}