Skip to content

Commit 743417a

Browse files
committed
Enable the on-disk topology cache by default (match the .NET client)
The .NET client enables the topology cache by default (DisableTopologyCache=false, TopologyCacheLocation=AppContext.BaseDirectory). Align the Python port so it has the same purpose/behaviour, not just the same mechanism: - Add the disable_topology_cache convention (default False), mirroring .NET DisableTopologyCache. - Default topology_cache_location to os.getcwd() (the closest zero-dependency analog of .NET's AppContext.BaseDirectory). - RequestExecutor gates both the write and the seed-from-cache on `not disable_topology_cache`. Every client now persists topology and, when its initial urls are unreachable on startup, seeds the last-known topology from disk. TestBase.tearDown already removes *topology files from the working directory, so the default-on behaviour leaves no test artifacts (verified across a broad sample; 0 files left behind).
1 parent e53ae1d commit 743417a

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

ravendb/documents/conventions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import inspect
4+
import os
45
import threading
56
from abc import abstractmethod, ABC
67
from datetime import timedelta, datetime
@@ -51,8 +52,10 @@ def __init__(self):
5152

5253
# Flags
5354
self.disable_topology_updates = False
54-
# Opt-in on-disk topology cache: directory to persist/read topology files, or None to disable.
55-
self.topology_cache_location: Optional[str] = None
55+
# On-disk topology cache (mirrors the .NET client): enabled by default. Topology is persisted to, and
56+
# - when the initial urls are unreachable on startup - seeded from topology_cache_location.
57+
self.disable_topology_cache = False
58+
self.topology_cache_location: Optional[str] = os.getcwd()
5659
self._optimistic_concurrency_mode = None
5760
# Track which setter the user touched so we can reject mixing them.
5861
self._use_optimistic_concurrency_was_set = False

ravendb/http/request_executor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def __supply_async():
417417

418418
self._topology_etag = self._node_selector.topology.etag
419419

420-
if self.conventions.topology_cache_location:
420+
if not self.conventions.disable_topology_cache and self.conventions.topology_cache_location:
421421
topology_local_cache.try_save(
422422
self.conventions.topology_cache_location,
423423
topology_local_cache.server_hash(parameters.node.url, self._database_name),
@@ -497,7 +497,7 @@ def __run(errors: list):
497497

498498
def _try_load_topology_from_cache(self, url):
499499
return topology_local_cache.try_load(
500-
self.conventions.topology_cache_location,
500+
None if self.conventions.disable_topology_cache else self.conventions.topology_cache_location,
501501
topology_local_cache.server_hash(url, self._database_name),
502502
topology_local_cache.DATABASE_TOPOLOGY_EXTENSION,
503503
)
@@ -1471,7 +1471,7 @@ def __supply_async():
14711471
new_topology = Topology(results.etag, nodes)
14721472
self._topology_etag = results.etag
14731473

1474-
if self.conventions.topology_cache_location:
1474+
if not self.conventions.disable_topology_cache and self.conventions.topology_cache_location:
14751475
topology_local_cache.try_save(
14761476
self.conventions.topology_cache_location,
14771477
topology_local_cache.server_hash(parameters.node.url),
@@ -1505,7 +1505,7 @@ def __supply_async():
15051505

15061506
def _try_load_topology_from_cache(self, url):
15071507
return topology_local_cache.try_load(
1508-
self.conventions.topology_cache_location,
1508+
None if self.conventions.disable_topology_cache else self.conventions.topology_cache_location,
15091509
topology_local_cache.server_hash(url),
15101510
topology_local_cache.CLUSTER_TOPOLOGY_EXTENSION,
15111511
)

0 commit comments

Comments
 (0)