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

Commit

Permalink
bug: [reset configuration cache when updating] (FF-2495) (#18)
Browse files Browse the repository at this point in the history
* bug: [reset configuration cache when updating] (FF-2495)

* bump to 0.2.5
  • Loading branch information
leoromanovsky authored Jun 21, 2024
1 parent cd47f76 commit 0397293
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/eppo_client/configuration_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ def retrieve_configuration(key)

def assign_configurations(configs)
@lock.with_write_lock do
# Create a temporary new cache and populate it.
new_cache = EppoClient::LRUCache.new(@cache.size)
configs.each do |key, config|
@cache[key] = config
new_cache[key] = config
end

# Replace the old cache with the new one.
# Performs an atomic swap.
@cache = new_cache
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/eppo_client/lru_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module EppoClient
# and re-inserting a key-value pair on access moves the key to the last position. When an
# entry is added and the cache is full, the first entry is removed.
class LRUCache
attr_reader :cache
attr_reader :cache, :size

# Creates a new LRUCache that can hold +size+ entries.
def initialize(size)
Expand Down
2 changes: 1 addition & 1 deletion lib/eppo_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module EppoClient
VERSION = '0.2.4'
VERSION = '0.2.5'
end
11 changes: 11 additions & 0 deletions spec/configuration_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@
expect(store.retrieve_configuration('item_to_be_evicted')).to be_nil
expect(store.retrieve_configuration("test-entry-#{TEST_MAX_SIZE - 1}")).to be(test_exp)
end

it 'uses the incoming configurations as the source of truth' do
store.assign_configurations({ 'item1' => test_exp, 'item2' => test_exp })

expect(store.retrieve_configuration('item1')).to be(test_exp)
expect(store.retrieve_configuration('item2')).to be(test_exp)

store.assign_configurations({ 'item1' => test_exp })
expect(store.retrieve_configuration('item1')).to be(test_exp)
expect(store.retrieve_configuration('item2')).to be_nil
end
end

0 comments on commit 0397293

Please sign in to comment.