from flask import request from src.cache.constants import DEFAULT_CACHE_MODE, CacheMode from src.cache.exceptions import UnsupportedCacheMode from src.config.base import ALLOW_CACHE_MODES def get_cache_mode(): """Get cache mode based on headers value and configuration.""" mode = request.headers.get("Cache-Mode") if not mode or not ALLOW_CACHE_MODES: return DEFAULT_CACHE_MODE if mode and not CacheMode.has(mode): raise UnsupportedCacheMode(f"Got unsupported cache mode value {mode}") return CacheMode(mode)