Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
backporting fix to stale configuration cache to v1.x.y branch (#39)
Browse files Browse the repository at this point in the history
* clear config store before loading new config (#30)

* bump version v1.3.2

* migrate cherry picked test case to RAC-format

---------

Co-authored-by: Sven Schmit <sven@geteppo.com>
  • Loading branch information
leoromanovsky and schmit authored May 23, 2024
1 parent a52c582 commit d3daac7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eppo_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from eppo_client.http_client import HttpClient, SdkParams
from eppo_client.read_write_lock import ReadWriteLock

__version__ = "1.3.1"
__version__ = "1.3.2"

__client: Optional[EppoClient] = None
__lock = ReadWriteLock()
Expand Down
1 change: 1 addition & 0 deletions eppo_client/configuration_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get_configuration(self, key: str) -> Optional[T]:
def set_configurations(self, configs: Dict[str, T]):
try:
self.__lock.acquire_write()
self.__cache.clear()
for key, config in configs.items():
self.__cache[key] = config
finally:
Expand Down
13 changes: 13 additions & 0 deletions test/configuration_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ def test_evicts_old_entries_when_max_size_exceeded():
assert (
store.get_configuration("test-entry-{}".format(TEST_MAX_SIZE - 1)) == test_exp
)


def test_evicts_old_entries_when_setting_new_flags():
store: ConfigurationStore[str] = ConfigurationStore(max_size=TEST_MAX_SIZE)

store.set_configurations({"flag": test_exp, "second_flag": test_exp})
assert store.get_configuration("flag") == test_exp
assert store.get_configuration("second_flag") == test_exp

# Updating the flags should evict flags that no longer exist
store.set_configurations({"flag": test_exp})
assert store.get_configuration("flag") == test_exp
assert store.get_configuration("second_flag") is None

0 comments on commit d3daac7

Please sign in to comment.