Skip to content

Commit 31d82b5

Browse files
Kristian NylundKristian Nylund
authored andcommitted
added expiry for in-memory state store
1 parent 016003f commit 31d82b5

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

text_2_sql/autogen/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies = [
1717
"text_2_sql_core",
1818
"sqlparse>=0.4.4",
1919
"nltk>=3.8.1",
20+
"cachetools>=5.5.1",
2021
]
2122

2223
[dependency-groups]

text_2_sql/autogen/src/autogen_text_2_sql/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33
from autogen_text_2_sql.autogen_text_2_sql import AutoGenText2Sql
4+
from autogen_text_2_sql.state_store import InMemoryStateStore
5+
46
from text_2_sql_core.payloads.interaction_payloads import (
57
UserMessagePayload,
68
DismabiguationRequestsPayload,
@@ -16,4 +18,5 @@
1618
"AnswerWithSourcesPayload",
1719
"ProcessingUpdatePayload",
1820
"InteractionPayload",
21+
"InMemoryStateStore",
1922
]

text_2_sql/autogen/src/autogen_text_2_sql/state_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC, abstractmethod
2+
from cachetools import TTLCache
23

34
class StateStore(ABC):
45
@abstractmethod
@@ -12,8 +13,7 @@ def save_state(self, thread_id, state):
1213

1314
class InMemoryStateStore(StateStore):
1415
def __init__(self):
15-
# Replace with a caching library or something to have some sort of expiry for entries so this doesn't grow forever
16-
self.cache = {}
16+
self.cache = TTLCache(maxsize=1000, ttl=4*60*60) # 4 hours
1717

1818
def get_state(self, thread_id):
1919
return self.cache.get(thread_id)

uv.lock

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)