{"record":{"id":"4e3f456ff3ed1d70","repo":"NanmiCoder/MediaCrawler","slug":"unknown-cache-type-cache-type","errorCode":null,"errorMessage":"Unknown cache type: {cache_type}","messagePattern":"Unknown cache type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"cache/cache_factory.py","lineNumber":49,"sourceCode":"    \"\"\"\n\n    @staticmethod\n    def create_cache(cache_type: str, *args, **kwargs):\n        \"\"\"\n        Create cache object\n        :param cache_type: Cache type\n        :param args: Arguments\n        :param kwargs: Keyword arguments\n        :return:\n        \"\"\"\n        if cache_type == 'memory':\n            from .local_cache import ExpiringLocalCache\n            return ExpiringLocalCache(*args, **kwargs)\n        elif cache_type == 'redis':\n            from .redis_cache import RedisCache\n            return RedisCache()\n        else:\n            raise ValueError(f'Unknown cache type: {cache_type}')\n","sourceCodeStart":31,"sourceCodeEnd":50,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/cache/cache_factory.py#L31-L50","documentation":"ValueError from CacheFactory.create_cache when cache_type is neither 'memory' nor 'redis'. The factory lazily imports ExpiringLocalCache for 'memory' and RedisCache for 'redis', and treats any other string as a programming/configuration error.","triggerScenarios":"Passing cache_type from config (e.g. CACHETYPE_STRING) with a typo like 'Memory', 'mem', 'local', or an empty string; adding a new cache backend (e.g. 'memcached') without extending the factory's if/elif chain.","commonSituations":"Editing the config file's cache type value; case mismatch between documented values and the code's exact lowercase literals; upgrading/downgrading versions where supported cache types changed.","solutions":["Set cache_type to exactly 'memory' or 'redis' (lowercase) in config/base_config.py or wherever create_cache is called.","If you need a new backend, add an elif branch mapping your type to its class before relying on it.","Log the incoming cache_type at startup so typos surface immediately."],"exampleFix":"# before\nCacheFactory.create_cache('mem')\n\n# after\nCacheFactory.create_cache('memory')","handlingStrategy":"type-guard","validationCode":"from cache.cache_factory import CacheFactory\nSUPPORTED = {'memory', 'redis'}\nif cache_type not in SUPPORTED:\n    raise SystemExit(f'cache type must be one of {sorted(SUPPORTED)}, got {cache_type!r}')\ncache = CacheFactory.create_cache(cache_type)","typeGuard":"def is_supported_cache(t: str) -> bool:\n    return isinstance(t, str) and t in {'memory', 'redis'}","tryCatchPattern":"try:\n    cache = CacheFactory.create_cache(cfg.CACHETYPE_STRING)\nexcept ValueError:\n    logger.error('bad cache type; defaulting to memory')\n    cache = CacheFactory.create_cache('memory')","preventionTips":["Validate config values against the supported set at startup","Use exact lowercase literals 'memory'/'redis'","Add a unit test enumerating supported cache types so new branches stay in sync"],"tags":["cache","configuration","valueerror","factory"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}