Skip to content

Commit 3c0e9cc

Browse files
committed
fixup(flagd): remove merge conflict error as stated by warber
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 755f04c commit 3c0e9cc

File tree

1 file changed

+17
-22
lines changed
  • providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers

1 file changed

+17
-22
lines changed

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/grpc.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,17 @@ def __init__(
5252
self.emit_provider_ready = emit_provider_ready
5353
self.emit_provider_error = emit_provider_error
5454
self.emit_provider_configuration_changed = emit_provider_configuration_changed
55+
self.cache: typing.Optional[BaseCacheImpl] = (
56+
LRUCache(maxsize=self.config.max_cache_size)
57+
if self.config.cache_type == CacheType.LRU
58+
else None
59+
)
5560
self.stub, self.channel = self._create_stub()
5661
self.retry_backoff_seconds = config.retry_backoff_ms * 0.001
5762
self.streamline_deadline_seconds = config.stream_deadline_ms * 0.001
5863
self.deadline = config.deadline * 0.001
5964
self.connected = False
6065

61-
self._cache: typing.Optional[BaseCacheImpl] = (
62-
LRUCache(maxsize=self.config.max_cache_size)
63-
if self.config.cache_type == CacheType.LRU
64-
else None
65-
)
66-
6766
def _create_stub(
6867
self,
6968
) -> typing.Tuple[evaluation_pb2_grpc.ServiceStub, grpc.Channel]:
@@ -74,24 +73,20 @@ def _create_stub(
7473
options=(("grpc.keepalive_time_ms", config.keep_alive),),
7574
)
7675
stub = evaluation_pb2_grpc.ServiceStub(channel)
76+
77+
if self.cache:
78+
self.cache.clear()
79+
7780
return stub, channel
7881

7982
def initialize(self, evaluation_context: EvaluationContext) -> None:
8083
self.connect()
81-
self.retry_backoff_seconds = 0.1
82-
self.connected = False
83-
84-
self._cache = (
85-
LRUCache(maxsize=self.config.max_cache_size)
86-
if self.config.cache_type == CacheType.LRU
87-
else None
88-
)
8984

9085
def shutdown(self) -> None:
9186
self.active = False
9287
self.channel.close()
93-
if self._cache:
94-
self._cache.clear()
88+
if self.cache:
89+
self.cache.clear()
9590

9691
def connect(self) -> None:
9792
self.active = True
@@ -164,9 +159,9 @@ def listen(self) -> None:
164159
def handle_changed_flags(self, data: typing.Any) -> None:
165160
changed_flags = list(data["flags"].keys())
166161

167-
if self._cache:
162+
if self.cache:
168163
for flag in changed_flags:
169-
self._cache.pop(flag)
164+
self.cache.pop(flag)
170165

171166
self.emit_provider_configuration_changed(ProviderEventDetails(changed_flags))
172167

@@ -217,8 +212,8 @@ def _resolve( # noqa: PLR0915 C901
217212
default_value: T,
218213
evaluation_context: typing.Optional[EvaluationContext],
219214
) -> FlagResolutionDetails[T]:
220-
if self._cache is not None and flag_key in self._cache:
221-
cached_flag: FlagResolutionDetails[T] = self._cache[flag_key]
215+
if self.cache is not None and flag_key in self.cache:
216+
cached_flag: FlagResolutionDetails[T] = self.cache[flag_key]
222217
cached_flag.reason = Reason.CACHED
223218
return cached_flag
224219

@@ -280,8 +275,8 @@ def _resolve( # noqa: PLR0915 C901
280275
variant=response.variant,
281276
)
282277

283-
if response.reason == Reason.STATIC and self._cache is not None:
284-
self._cache.insert(flag_key, result)
278+
if response.reason == Reason.STATIC and self.cache is not None:
279+
self.cache.insert(flag_key, result)
285280

286281
return result
287282

0 commit comments

Comments
 (0)