microsoft/qlib · error · KeyError

Unknown memcache unit

Error message

Unknown memcache unit

What it means

Error "Unknown memcache unit" thrown in microsoft/qlib.

Source

Thrown at qlib/data/cache.py:173

            klass = MemCacheLengthUnit
        elif limit_type == "sizeof":
            klass = MemCacheSizeofUnit
        else:
            raise ValueError(f"limit_type must be length or sizeof, your limit_type is {limit_type}")

        self.__calendar_mem_cache = klass(size_limit)
        self.__instrument_mem_cache = klass(size_limit)
        self.__feature_mem_cache = klass(size_limit)

    def __getitem__(self, key):
        if key == "c":
            return self.__calendar_mem_cache
        elif key == "i":
            return self.__instrument_mem_cache
        elif key == "f":
            return self.__feature_mem_cache
        else:
            raise KeyError("Unknown memcache unit")

    def clear(self):
        self.__calendar_mem_cache.clear()
        self.__instrument_mem_cache.clear()
        self.__feature_mem_cache.clear()


class MemCacheExpire:
    CACHE_EXPIRE = C.mem_cache_expire

    @staticmethod
    def set_cache(mem_cache, key, value):
        """set cache

        :param mem_cache: MemCache attribute('c'/'i'/'f').
        :param key: cache key.
        :param value: cache value.
        """

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use a supported memcache unit (e.g. a positive int for size limit or the supported unit strings).
  2. Check your memcache configuration and set a valid unit for cache size/length.

When it happens

Trigger: This error is raised at qlib/data/cache.py:173 when the guard condition fails: "Unknown memcache unit". It triggers when the code path receives input or a state that violates the precondition checked at this point — e.g. an unimplemented abstract method being called, an unsupported argument type/value, or an invalid configuration. To avoid it, satisfy the documented precondition before this call: implement the required method in your subclass, or pass a supported value of the expected type as described by the message.

Common situations: See trigger scenarios.


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/6106ca2d4c1f94d7. Report an issue: GitHub.