Coverage for mcpgateway / cache / __init__.py: 54%
35 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 03:05 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 03:05 +0000
1# -*- coding: utf-8 -*-
2"""Location: ./mcpgateway/cache/__init__.py
3Copyright 2025
4SPDX-License-Identifier: Apache-2.0
5Authors: Mihai Criveti
7Cache Package.
8Provides caching components for ContextForge including:
9- Resource content caching
10- Session registry for MCP connections
11- GlobalConfig caching for passthrough headers
12- Auth caching for user, team, and token revocation data
13- Registry caching for tools, prompts, resources, agents, servers, gateways
14- Admin stats caching for dashboard statistics
16Note: Imports are lazy to avoid circular dependencies with services.
17"""
19from typing import TYPE_CHECKING
21__all__ = [
22 "A2AStatsCache",
23 "a2a_stats_cache",
24 "AdminStatsCache",
25 "admin_stats_cache",
26 "AuthCache",
27 "auth_cache",
28 "CachedAuthContext",
29 "GlobalConfigCache",
30 "global_config_cache",
31 "MetricsCache",
32 "metrics_cache",
33 "RegistryCache",
34 "registry_cache",
35 "ToolLookupCache",
36 "tool_lookup_cache",
37 "ResourceCache",
38 "SessionRegistry",
39]
41# Lazy imports to avoid circular dependencies
42# When services import cache.global_config_cache, we don't want to
43# trigger imports of ResourceCache/SessionRegistry which depend on services
45if TYPE_CHECKING:
46 from mcpgateway.cache.a2a_stats_cache import A2AStatsCache, a2a_stats_cache
47 from mcpgateway.cache.admin_stats_cache import AdminStatsCache, admin_stats_cache
48 from mcpgateway.cache.auth_cache import AuthCache, auth_cache, CachedAuthContext
49 from mcpgateway.cache.global_config_cache import GlobalConfigCache, global_config_cache
50 from mcpgateway.cache.metrics_cache import MetricsCache, metrics_cache
51 from mcpgateway.cache.registry_cache import RegistryCache, registry_cache
52 from mcpgateway.cache.tool_lookup_cache import ToolLookupCache, tool_lookup_cache
53 from mcpgateway.cache.resource_cache import ResourceCache
54 from mcpgateway.cache.session_registry import SessionRegistry
57def __getattr__(name: str):
58 """Lazy import handler for cache submodules.
60 Args:
61 name: The attribute name being accessed.
63 Returns:
64 The requested cache class or instance.
66 Raises:
67 AttributeError: If the requested attribute is not found.
68 """
69 # pylint: disable=import-outside-toplevel
70 if name in ("A2AStatsCache", "a2a_stats_cache"):
71 from mcpgateway.cache.a2a_stats_cache import A2AStatsCache, a2a_stats_cache
73 return a2a_stats_cache if name == "a2a_stats_cache" else A2AStatsCache
74 if name in ("AdminStatsCache", "admin_stats_cache"):
75 from mcpgateway.cache.admin_stats_cache import AdminStatsCache, admin_stats_cache
77 return admin_stats_cache if name == "admin_stats_cache" else AdminStatsCache
78 if name in ("AuthCache", "auth_cache", "CachedAuthContext"):
79 from mcpgateway.cache.auth_cache import AuthCache, auth_cache, CachedAuthContext
81 if name == "auth_cache":
82 return auth_cache
83 if name == "CachedAuthContext":
84 return CachedAuthContext
85 return AuthCache
86 if name in ("GlobalConfigCache", "global_config_cache"):
87 from mcpgateway.cache.global_config_cache import GlobalConfigCache, global_config_cache
89 return global_config_cache if name == "global_config_cache" else GlobalConfigCache
90 if name in ("MetricsCache", "metrics_cache"):
91 from mcpgateway.cache.metrics_cache import MetricsCache, metrics_cache
93 return metrics_cache if name == "metrics_cache" else MetricsCache
94 if name in ("RegistryCache", "registry_cache"):
95 from mcpgateway.cache.registry_cache import RegistryCache, registry_cache
97 return registry_cache if name == "registry_cache" else RegistryCache
98 if name in ("ToolLookupCache", "tool_lookup_cache"):
99 from mcpgateway.cache.tool_lookup_cache import ToolLookupCache, tool_lookup_cache
101 return tool_lookup_cache if name == "tool_lookup_cache" else ToolLookupCache
102 if name == "ResourceCache":
103 from mcpgateway.cache.resource_cache import ResourceCache
105 return ResourceCache
106 if name == "SessionRegistry":
107 from mcpgateway.cache.session_registry import SessionRegistry
109 return SessionRegistry
110 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")