import copy, json, os CONFIGS_DIR = os.environ.get('ROUTLIN_LOCATION', '/routlin_location') CONFIG_FILE = f'{CONFIGS_DIR}/config.json' CAPTIVE_QUEUE = f'{CONFIGS_DIR}/.captive-queue' _config_cache = None _config_mtime = None def load_config(): global _config_cache, _config_mtime try: mtime = os.path.getmtime(CONFIG_FILE) if _config_cache is not None and mtime == _config_mtime: return copy.deepcopy(_config_cache) with open(CONFIG_FILE) as f: data = json.load(f) _config_cache = data _config_mtime = mtime return copy.deepcopy(data) except Exception: return {}