MCPcopy Create free account
hub / github.com/GuDaStudio/GrokSearch / SourcesCache

Class SourcesCache

src/grok_search/sources.py:32–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31
32class SourcesCache:
33 def __init__(self, max_size: int = 256):
34 self._max_size = max_size
35 self._lock = asyncio.Lock()
36 self._cache: OrderedDict[str, list[dict]] = OrderedDict()
37
38 async def set(self, session_id: str, sources: list[dict]) -> None:
39 async with self._lock:
40 self._cache[session_id] = sources
41 self._cache.move_to_end(session_id)
42 while len(self._cache) > self._max_size:
43 self._cache.popitem(last=False)
44
45 async def get(self, session_id: str) -> list[dict] | None:
46 async with self._lock:
47 sources = self._cache.get(session_id)
48 if sources is None:
49 return None
50 self._cache.move_to_end(session_id)
51 return sources
52
53
54def merge_sources(*source_lists: list[dict]) -> list[dict]:

Callers 1

server.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected