File size: 658 Bytes
82e122c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from functools import lru_cache

from app.services.nl2sql_service import NL2SQLService
from app.cache import NL2SQLCache
from app.settings import get_settings


@lru_cache()
def get_nl2sql_service() -> NL2SQLService:
    """
    Singleton-ish NL2SQLService for the FastAPI app.

    Uses centralized Settings so configuration is loaded once and injected.
    """
    settings = get_settings()
    return NL2SQLService(settings=settings)


@lru_cache()
def get_cache() -> NL2SQLCache:
    """
    Singleton in-memory cache for NL2SQL responses.
    TTL is intentionally short; this is a per-process best-effort cache.
    """
    return NL2SQLCache(ttl=15.0)