def _build_cache(self, cache_size: int, cache_type: MarqoCacheType) -> Optional[MarqoAbstractCache]:
        """Return a cache instance based on the cache type and size.

        Args:
            cache_size: The maximum size of the cache.
            cache_type: The type of the cache.

        Returns:
            A cache instance based on the cache type and size. None if the cache_size is 0.

        Raises:
            EnvVarError: If the cache size or type is invalid.
        """
        if not isinstance(cache_size, int) or cache_size < 1:
            raise EnvVarError(f"Invalid cache size: {cache_size}. Must be a positive integer.")

        if cache_type not in self._CACHE_TYPES_MAPPING:
            raise EnvVarError(f"Invalid cache type: {cache_type}. "
                              f"Must be one of {self._CACHE_TYPES_MAPPING.keys()}.")
        cache = self._CACHE_TYPES_MAPPING[cache_type](maxsize=cache_size)
        logger.info(f'Built inference cache with type {cache_type} and size {cache_size}')
        return cache
Return a cache instance based on the cache type and size.

        Args:
            cache_size: The maximum size of the cache.
            cache_type: The type of the cache.

        Returns:
            A cache instance based on the cache type and size. None if the cache_size is 0.

        Raises:
            EnvVarError: If the cache size or type is invalid.
        
src/marqo/inference/inference_cache/marqo_inference_cache.py