MCPcopy Index your code
hub / github.com/dataease/SQLBot / init_sqlbot_cache

Function init_sqlbot_cache

backend/common/core/sqlbot_cache.py:127–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

125
126
127def init_sqlbot_cache():
128 cache_type: str = settings.CACHE_TYPE
129 if cache_type == "memory":
130 FastAPICache.init(InMemoryBackend())
131 SQLBotLogUtil.info("SQLBot 使用内存缓存, 仅支持单进程模式")
132 elif cache_type == "redis":
133 from fastapi_cache.backends.redis import RedisBackend
134 import redis.asyncio as redis
135 from redis.asyncio.connection import ConnectionPool
136 redis_url = settings.CACHE_REDIS_URL or "redis://localhost:6379/0"
137 pool = ConnectionPool.from_url(url=redis_url)
138 redis_client = redis.Redis(connection_pool=pool)
139 FastAPICache.init(RedisBackend(redis_client), prefix="sqlbot-cache")
140 SQLBotLogUtil.info(f"SQLBot 使用Redis缓存, 可使用多进程模式")
141 else:
142 SQLBotLogUtil.warning("SQLBot 未启用缓存, 可使用多进程模式")
143
144
145def is_cache_initialized() -> bool:

Callers 1

lifespanFunction · 0.90

Calls 3

warningMethod · 0.80
initMethod · 0.65
infoMethod · 0.45

Tested by

no test coverage detected