Skip to content

Commit 5b85877

Browse files
committed
standardize no ttl
1 parent ae42b8d commit 5b85877

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ asyncio.run(main())
368368

369369
#### Cache TTL Configuration
370370

371-
When using Replicator Mode, you should set the SDK's cache TTL to match the replicator's cache TTL. The replicator defaults to an unlimited cache TTL (`0`). If the SDK uses a shorter TTL (the default is 24 hours), locally updated cache entries will be written back with the shorter TTL and eventually evicted from the shared cache.
371+
When using Replicator Mode, you should set the SDK's cache TTL to match the replicator's cache TTL. The replicator defaults to an unlimited cache TTL. If the SDK uses a shorter TTL (the default is 24 hours), locally updated cache entries will be written back with the shorter TTL and eventually evicted from the shared cache.
372372

373373
To match the replicator's default unlimited TTL:
374374

@@ -377,7 +377,7 @@ config = AsyncSchematicConfig(
377377
use_datastream=True,
378378
datastream=DataStreamConfig(
379379
replicator_mode=True,
380-
cache_ttl=0, # Unlimited, matching the replicator default
380+
cache_ttl=None, # Unlimited, matching the replicator default
381381
),
382382
)
383383
```
@@ -389,7 +389,7 @@ config = AsyncSchematicConfig(
389389
use_datastream=True,
390390
datastream=DataStreamConfig(
391391
replicator_mode=True,
392-
cache_ttl=0,
392+
cache_ttl=None,
393393
replicator_health_url="http://my-replicator:8090/ready",
394394
replicator_health_check=60_000, # 60 seconds, in milliseconds
395395
),

src/schematic/datastream/datastream_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class DataStreamClientOptions:
8888
api_key: str
8989
logger: logging.Logger
9090
base_url: Optional[str] = None
91-
cache_ttl: int = DEFAULT_TTL_MS
91+
cache_ttl: Optional[int] = DEFAULT_TTL_MS
9292

9393
# Custom cache providers (override defaults)
9494
company_cache: Optional[AsyncCacheProvider[Any]] = None
@@ -174,14 +174,15 @@ def __init__(self, options: DataStreamClientOptions) -> None:
174174
)
175175

176176
# Cache providers
177-
flag_ttl = max(MAX_CACHE_TTL_MS, self._cache_ttl)
178-
self._company_cache: AsyncCacheProvider[RulesengineCompany] = options.company_cache or AsyncLocalCache(ttl=self._cache_ttl)
179-
self._user_cache: AsyncCacheProvider[RulesengineUser] = options.user_cache or AsyncLocalCache(ttl=self._cache_ttl)
177+
local_ttl = self._cache_ttl if self._cache_ttl is not None else DEFAULT_TTL_MS
178+
flag_ttl = max(MAX_CACHE_TTL_MS, local_ttl)
179+
self._company_cache: AsyncCacheProvider[RulesengineCompany] = options.company_cache or AsyncLocalCache(ttl=local_ttl)
180+
self._user_cache: AsyncCacheProvider[RulesengineUser] = options.user_cache or AsyncLocalCache(ttl=local_ttl)
180181
self._flag_cache: AsyncCacheProvider[RulesengineFlag] = options.flag_cache or AsyncLocalCache(ttl=flag_ttl)
181182

182183
# Key -> ID mapping caches (two-level caching)
183-
self._company_key_cache: AsyncCacheProvider[str] = options.company_lookup_cache or AsyncLocalCache(ttl=self._cache_ttl)
184-
self._user_key_cache: AsyncCacheProvider[str] = options.user_lookup_cache or AsyncLocalCache(ttl=self._cache_ttl)
184+
self._company_key_cache: AsyncCacheProvider[str] = options.company_lookup_cache or AsyncLocalCache(ttl=local_ttl)
185+
self._user_key_cache: AsyncCacheProvider[str] = options.user_lookup_cache or AsyncLocalCache(ttl=local_ttl)
185186

186187
# WebSocket client
187188
self._ws_client: Optional[DatastreamWSClient] = None

0 commit comments

Comments
 (0)